gpt4 book ai didi

r - 如何避免igraph中的双箭头

转载 作者:行者123 更新时间:2023-12-04 12:14:35 25 4
gpt4 key购买 nike

使用以下代码

library(igraph)

actors <- data.frame(name=c("a","b","c","d","e","f","g","h"))
relations <- data.frame(from=c("a", "a", "b", "b",
"b", "c", "d","d",
"g","e","g","d"),
to =c("d", "e", "c", "e",
"g", "f", "f", "g",
"h","b","d","a"),
weight = c(14,30,25,3,5,6,4,13,2,6,10,10))
g <- graph_from_data_frame(relations, directed=TRUE, vertices=actors)
test.layout <- layout_(g,with_dh(weight.edge.lengths = edge_density(g)/1000))
plot(g,vertex.size=30,edge.arrow.size= 0.5,edge.label = relations$weight,
layout = test.layout)
我产生加权有向图
enter image description here
我想避免某些边缘末端的双箭头。相反,我想看到两个不同的边(例如从 d 到 a 和从 a 到 d)。

最佳答案

您在生成布局之前没有设置随机种子,因此我无法准确了解您的布局。尽管如此,您可以通过使用 edge.curved 获得两个独立的边。论据 igraph.plot .

ENDS = ends(g, E(g))
Curv = rep(F, nrow(ENDS))
for(i in 1:nrow(ENDS)) {
Curv[i] = are.connected(g, ENDS[i,2], ENDS[i,1]) }

plot(g,vertex.size=30,edge.arrow.size=0.5,edge.label = relations$weight,
layout = test.layout, edge.curved=Curv)
Graph with curved edges

关于r - 如何避免igraph中的双箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69605970/

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