我有一个与此类似的数据集。
library(igraph)
df <- data.frame(Account= c('Luca', 'Alberto', 'Luisa', 'Marcello', 'Tania'),
friend = c('Alberto', 'Luisa', 'Tania', 'Alberto', 'Luisa'))
edges1 = data.frame("from" =df$Account , "to" =df$friend , stringsAsFactors = F )
net <- graph_from_data_frame(d= edges1, directed = T)
V(net)$degree <- degree(net)
plot(net, vertex.size=20,
vertex.color=rainbow(11),
edge.arrow.width=0.7,
edge.lty= 6)
我想将每条边的颜色与其起始节点的颜色相同。例如,来自 Luca 的每个链接为红色,来自 Luisa 的每个链接为黄色。 找不到任何相关信息,提前致谢
最佳答案
在问题中,顶点颜色是在 plot
命令中设置的,因此它们不是图形的一部分。相反,在图形本身中设置顶点颜色,然后根据这些设置边缘颜色。
V(net)$color <- rainbow(ecount(net))
E(net)$color <- tail_of(net, E(net))$color
plot(net)
关于r - 将边着色为与 igraph 中节点相同的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65634065/