在igraph中生成社区图

在igraph中生成社区图

本文介绍了在igraph中生成社区图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been searching for an answer to this question but could not find any mention, so I decided to post here. I am trying to see if igraph or any packages provide a simple way to create a "community graph" where each node represents a community in the network and the ties represent ties between the communities. I can get the community detection algorithm to work fine in igraph, but I could not find a way to collapse the results to just show connections between each community. Any assistance would be appreciated.

推荐答案

您可以简单地使用 contract.vertices()函数.这将顶点组收缩为单个顶点,基本上与您想要的方式相同.例如.

You can simply use the contract.vertices() function. This contracts groups of vertices into a single vertex, essentially the same way you want it. E.g.

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)

这篇关于在igraph中生成社区图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:40