在igraph中按簇折叠图

9

我希望将一个图形折叠成其相应的社区/集群。让我用以下玩具示例来说明:

set.seed(123)

#toy graph
g <- barabasi.game(10) %>%
  as.undirected()

#identify communities 
c_g <- fastgreedy.community(g) 

以下图表显示有三个社区。

enter image description here

我希望你能够减少顶点的折叠,使得结果图中的顶点对应于之前顶点的成员资格。请参见该图。

enter image description here

我对igraph包很新,不熟悉处理igraph对象的最佳方法。

1个回答

11

您可以尝试使用contract

library(igraph)
set.seed(123)
g <- barabasi.game(10) %>% as.undirected()
c_g <- fastgreedy.community(g) 
V(g)$name <- letters[1:vcount(g)]

g2 <- contract(g, membership(c_g), vertex.attr.comb=toString)

par(mfrow=c(1,2))
plot(g, vertex.color=membership(c_g))
plot(simplify(g2), vertex.color=1:vcount(g2))

输入图片描述


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接