gpt4 book ai didi

r - 绘制一个图表,表示每条弧线的权重

转载 作者:行者123 更新时间:2023-12-02 15:44:27 24 4
gpt4 key购买 nike

我想画一个小图来指示它在弧上的权重。例如下面的代码:

library(igraph)
actors <- data.frame(name=c("0","1","2", "3", "4", "5","6"))
relations <- data.frame(from=c("0", "0", "1", "2", "3", "3","4","5","4"),
to=c("1", "2", "3", "3", "5", "4","5","6","6"),
weight=c(2,6,5,8,15,10,6,6,2))
g <- graph_from_data_frame(relations, directed=F, vertices=actors)
plot(g)

绘制没有权重信息的图表: enter image description here我怎样才能在图片上插入这些信息?

最佳答案

您可以使用set_edge_attrweight分配给width(或label)属性,例如,

g %>%
set_edge_attr(name = "width", value = relations$weight) %>%
plot()

g %>%
set_edge_attr(name = "label", value = relations$weight) %>%
plot()

关于r - 绘制一个图表,表示每条弧线的权重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74808967/

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