SOUser
SOUser

Reputation: 610

plotting communities in iGraph

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) 

Upvotes: 0

Views: 5332

Answers (1)

Tam&#225;s
Tam&#225;s

Reputation: 48041

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.

Upvotes: 4

Related Questions