【问题标题】:Multiple directed edges igraph多个有向边 igraph
【发布时间】:2016-02-11 18:02:02
【问题描述】:

我想将下图中顶点 1 和 2 之间的边表示为两条独立的边,箭头方向相反。

require(igraph) 
e <-  c(1,2, 2,3, 3,1, 3,4 , 4,1 , 2,1)
g <- graph(e, n=5, directed = TRUE)
tkplot(g, layout=layout.circle )

我得到的只是一个边缘,两端都有一个箭头。这应该很容易,但我在任何地方都没有找到它,也无法弄清楚。任何的想法?

【问题讨论】:

  • 我只能想到edge.curved=rep(0.5, ecount(g)),它使边缘弯曲,但我希望它们是直的。
  • 我认为 igraph 支持节点之间的多重边——也许尝试创建两个相反方向的定向边?
  • 方向边?在e &lt;- c(1,2, 2,3, 3,1, 3,4 , 4,1 , 2,1) 中有从 1 到 2(前两个)和从 2 到 1(后两个)的边。或者你所说的方向边缘是什么意思?
  • 是的,这就是我的意思。但我自己没试过……
  • 这是两条独立的边。 igraph 恰好将它们绘制在彼此的顶部,因此您将它们视为带有两个箭头的单边。不幸的是,igraph 中无法将它们绘制为两个 边,因此您最好的选择仍然是edge.curved。您可以将“单”边设置为 0.0,将两个方向上的边设置为 0.5。

标签: r plot igraph tkplot


【解决方案1】:

您应该绘制带有弯曲边缘的图形。请注意,在plot() 中,您使用edge.curved 进行曲线,但单独曲线边缘的边缘属性应仅为curved

下面的函数curve.reciprocal.edges() 我是在找到 Sacha Epskamp 的 this answer 之后写的,他显然已经写了一个包,qgraph,如果你的需求超出了可以达到的范围,你可能会发现它很有用:

require(igraph)
e <-  c(1,2, 2,3, 3,1, 3,4 , 4,1 , 2,1)
g <- graph(e, n=5, directed = TRUE)

curve.reciprocal.edges <- function(g, curve=.3){
    # Return a graph where the edge-attribute $curved is reset to highlight reciprocal edges
    el <- t(apply(get.edgelist(g),1,sort))
    E(g)$curved <- 0
    E(g)[duplicated(el) | duplicated(el,fromLast =TRUE)]$curved <- curve
    (g)
}

plot(g, layout=layout.circle, edge.curved=.2)
plot(curve.reciprocal.edges(g), layout=layout.circle)

【讨论】:

    猜你喜欢
    • 2019-06-19
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多