You can simply use the contract.vertices () function. These are groups of vertex contracts at one vertex, essentially the same as you want it. For example.
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)
Gabor Csardi
source share