我一直在寻找这个问题的答案,但是没有发现任何提及,所以我决定在这里发布。我正在尝试查看igraph或任何包是否提供了创建“社区图”的简单方法,其中每个节点表示网络中的一个社区,联系表示社区之间的联系。我能够让igraph中的社区检测算法正常工作,但是我找不到一种方法来折叠结果,以仅显示每个社区之间的联系。任何帮助将不胜感激。
我一直在寻找这个问题的答案,但是没有发现任何提及,所以我决定在这里发布。我正在尝试查看igraph或任何包是否提供了创建“社区图”的简单方法,其中每个节点表示网络中的一个社区,联系表示社区之间的联系。我能够让igraph中的社区检测算法正常工作,但是我找不到一种方法来折叠结果,以仅显示每个社区之间的联系。任何帮助将不胜感激。
library(igraph)
## create example graph
g1 <- graph.full(5)
V(g1)$name <- 1:5
g2 <- graph.full(5)
V(g2)$name <- 6:10
g3 <- graph.ring(5)
V(g3)$name <- 11:15
g <- g1 %du% g2 %du% g3 + edge('1', '6') + edge('1', '11')
## Community structure
fc <- fastgreedy.community(g)
## Create community graph, edge weights are the number of edges
cg <- contract.vertices(g, membership(fc))
E(cg)$weight <- 1
cg2 <- simplify(cg, remove.loops=FALSE)
## Plot the community graph
plot(cg2, edge.label=E(cg2)$weight, margin=.5, layout=layout.circle)