plotting communities in iGraph

蓝咒 提交于 2019-12-05 10:46:33

问题


I would like to reproduce the kind of "community summary" graph like on page 6 of this paper: http://arxiv.org/pdf/0803.0476v2.pdf

First a community algorithm is employed on the graph, e.g.:

  wc <- walktrap.community(subgraph)
  mc <- multilevel.community(subgraph)

Then the vertices are grouped according to community. The size of the community node is a function of the membership size and the edge width is a function of the total edges going from any member of community A to community B.

Please note I don't just want to encode community as color or convex hulls like this:

V(inSubGraph)$color <- commObj$membership+1
plot.igraph( inSubGraph, vertex.color = V(inSubGraph)$color)

or with the convex hulls:

 plot(commObj, inSubGraph) 

回答1:


Use the contract.vertices function with the membership vector that the community detection method provides, followed by simplify. In particular:

  1. Assign a numeric vertex attribute with a value of 1 to each vertex as follows: V(g)$size = 1

  2. Assign a numeric edge attribute with a value of 1 to each edge as follows: E(g)$count = 1

  3. Contract the communities into vertices as follows: comm.graph <- contract.vertices(g, wc$membership, vertex.attr.comb=list(size="sum", "ignore")); basically this specifies that the size attribute of the vertices being contracted should be summed and every other vertex attribute should be ignored. (See ?attribute.combination in R for more details). This call contracts the vertices but leaves the original edges so you now have as many edges between the vertices as there were in the original graph between the communities.

  4. Collapse the multiple edges as follows: comm.graph <- simplify(comm.graph, remove.loops=FALSE, edge.attr.comb=list(count="sum", "ignore")).

You now have a graph named comm.graph where the vertices represent the communities of the original graph, the size vertex attribute corresponds to the number of vertices in each community in the original graph, and the count edge attribute corresponds to the number of edges between communities in the original graph.



来源:https://stackoverflow.com/questions/20829387/plotting-communities-in-igraph

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