kri*_*nab 9 r social-networking igraph
我一直在寻找这个问题的答案,但找不到任何提及,所以我决定在这里发帖.我试图看看igraph或任何软件包是否提供了一种创建"社区图"的简单方法,其中每个节点代表网络中的社区,并且关系代表社区之间的联系.我可以让社区检测算法在igraph中正常工作,但我找不到一种方法来折叠结果,只显示每个社区之间的连接.任何援助将不胜感激.
Gab*_*rdi 21
您只需使用contract.vertices()函数即可.这会将顶点组合并到一个顶点,基本上与您想要的方式相同.例如
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)
Run Code Online (Sandbox Code Playgroud)