0

I am trying to create a dendrogram of the communities only of a network. The example code below gives me a dendrogram of all the nodes, but as I work with a relatively large dataset, I would like to create a dendrogram of only the comunities,so that I would have a smaller dendrogram with only the communities, is this possible?

library(igraph)
set.seed(1)    
g001 <- erdos.renyi.game(100, 1/10, directed = FALSE)

fc01 <- fastgreedy.community(g001)
colors <- rainbow(max(membership(fc01)))
plot(g001, vertex.size=2, vertex.label=NA, vertex.color=colors[membership(fc01)] )

dendPlot(fc01, mode="phylo", cex=1)

Thank you.

Nick
  • 1,086
  • 7
  • 21
user3731465
  • 93
  • 1
  • 7

1 Answers1

0

The dendrogram class has a cut function you can use to split up a dendrogram at a certain height. The community algorithm seems to use heights based on how many objects there are. Therefore, given your fc01 object above, you can split it into subgroups with

ss01 <- cut(as.dendrogram(fc01), h=length(membership(fc01))-length(fc01))$lower

That created 5 groups for me. We can plot the entire set and the 5 subsets with

layout(matrix(1:6, nrow=2))
dendPlot(fc01, mode="hclust")
lapply(ss01, plot, cex=1)

So each sub-graph is in ss01[[1]], ss02[[2]], etc...

MrFlick
  • 195,160
  • 17
  • 277
  • 295