How to colour edges within community clusters in igraph

旧巷老猫 提交于 2019-12-06 22:49:39

The following should work:

library(igraph)
g <- watts.strogatz.game(1, 100, 5, 0.05)
clp <- cluster_label_prop(g)
V(g)$community <- clp$membership
rain <- rainbow(14, alpha=.5)
V(g)$color <- rain[V(g)$community]

E(g)$color <- apply(as.data.frame(get.edgelist(g)), 1, 
                function(x) ifelse(V(g)$community[x[1]] == V(g)$community[x[2]], 
                                   rain[V(g)$community[x[1]]], '#00000000'))
plot(g, vertex.size=4, vertex.label=NA, edge.color=E(g)$color)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!