9

我一直在寻找这个问题的答案,但找不到任何提及,所以我决定在这里发帖。我正在尝试查看 igraph 或任何软件包是否提供了一种简单的方法来创建“社区图”,其中每个节点代表网络中的一个社区,而关系代表社区之间的关系。我可以让社区检测算法在 igraph 中正常工作,但我找不到一种方法来折叠结果以仅显示每个社区之间的联系。任何援助将不胜感激。

4

1 回答 1

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)
于 2012-10-02T23:36:02.613 回答