gpt4 book ai didi

r - 多有向边 igraph

转载 作者:行者123 更新时间:2023-12-03 15:54:51 26 4
gpt4 key购买 nike

我想将下图中顶点 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 )

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

最佳答案

您应该绘制带有弯曲边缘的图形。请注意,在 plot() , 你用 edge.curved 曲线,但单独曲线边缘的边缘属性应该是 curved只要。

下面的函数curve.reciprocal.edges()找到后写了this answer作者:Sacha Epskamp,显然写了一个包,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)

关于r - 多有向边 igraph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35346750/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com