简体   繁体   English

在社区而不是igraph中的节点上创建树状图

[英]Create dendrogram on communities, not nodes in igraph

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. 谢谢。

The dendrogram class has a cut function you can use to split up a dendrogram at a certain height. 树状图类具有cut功能,您可以使用该功能在特定高度将树状图拆分。 The community algorithm seems to use heights based on how many objects there are. community算法似乎基于存在的对象数来使用高度。 Therefore, given your fc01 object above, you can split it into subgroups with 因此,鉴于上面的fc01对象,您可以将其分为以下几个子组:

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

That created 5 groups for me. 那为我创造了5个小组。 We can plot the entire set and the 5 subsets with 我们可以绘制整个集合和5个子集

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... 因此每个子图都在ss01[[1]]ss02[[2]]等中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM