在igraph中按簇折叠图 [英] Collapsing graph by clusters in igraph

查看:96
本文介绍了在igraph中按簇折叠图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个图折叠到其各自的社区/集群中.让我用下面的玩具示例来说明这一点:

I want to collapse a graph into its respective communities/clusters. Let me illustrate this with the following toy example:

set.seed(123)

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

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

有三个社区,如下图所示.

There are three communities, as seen in the following graph.

我想减少顶点的折叠,以使结果图中的顶点对应于先前顶点的隶属关系.参见图表.

I want to reduce the collapse the vertices so that vertices in the resulting graph correspond to the membership of the previous vertices. See the graph.

我是igraph包的新手,我不熟悉处理igraph对象的最佳方法.

I'm new to the igraph package and I'm not familiar with the best way of dealing with igraph objects.

推荐答案

您可以尝试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))

这篇关于在igraph中按簇折叠图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆