在iGraph中绘制社区 [英] plotting communities in iGraph

查看:82
本文介绍了在iGraph中绘制社区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重现类似于本文第6页的社区摘要"图: http://arxiv.org/pdf/0803.0476v2.pdf

I would like to reproduce the kind of "community summary" graph like on page 6 of this paper: http://arxiv.org/pdf/0803.0476v2.pdf

首先在图上使用社区算法,例如:

First a community algorithm is employed on the graph, e.g.:

  wc <- walktrap.community(subgraph)
  mc <- multilevel.community(subgraph)

然后根据社区将顶点分组.社区节点的大小是成员资格大小的函数,边缘宽度是从社区A的任何成员到社区B的总边的函数.

Then the vertices are grouped according to community. The size of the community node is a function of the membership size and the edge width is a function of the total edges going from any member of community A to community B.

请注意我不只是想将社区编码为彩色或凸包,如下所示:

V(inSubGraph)$color <- commObj$membership+1
plot.igraph( inSubGraph, vertex.color = V(inSubGraph)$color)

或带有凸包:

 plot(commObj, inSubGraph) 

推荐答案

对社区检测方法提供的成员矢量使用contract.vertices函数,后跟simplify.特别是:

Use the contract.vertices function with the membership vector that the community detection method provides, followed by simplify. In particular:

  1. 为每个顶点分配一个值为1的数字顶点属性,如下所示:V(g)$size = 1

为每个边分配一个值为1的数字边属性,如下所示:E(g)$count = 1

Assign a numeric edge attribute with a value of 1 to each edge as follows: E(g)$count = 1

按如下所示将社区收缩为顶点:comm.graph <- contract.vertices(g, wc$membership, vertex.attr.comb=list(size="sum", "ignore"));基本上,这指定应该对要收缩的顶点的size属性求和,而忽略所有其他顶点属性. (有关更多详细信息,请参见R中的?attribute.combination).此调用会收缩顶点,但保留原始边缘,因此您现在在顶点之间的边缘与社区之间原始图中的边缘一样多.

Contract the communities into vertices as follows: comm.graph <- contract.vertices(g, wc$membership, vertex.attr.comb=list(size="sum", "ignore")); basically this specifies that the size attribute of the vertices being contracted should be summed and every other vertex attribute should be ignored. (See ?attribute.combination in R for more details). This call contracts the vertices but leaves the original edges so you now have as many edges between the vertices as there were in the original graph between the communities.

按如下所示折叠多个边:comm.graph <- simplify(comm.graph, remove.loops=FALSE, edge.attr.comb=list(count="sum", "ignore")).

Collapse the multiple edges as follows: comm.graph <- simplify(comm.graph, remove.loops=FALSE, edge.attr.comb=list(count="sum", "ignore")).

您现在有了一个名为comm.graph的图,其中顶点表示原始图的社区,size顶点属性对应于原始图中每个社区中的顶点数,而count边属性对应于原始图中社区之间的边数.

You now have a graph named comm.graph where the vertices represent the communities of the original graph, the size vertex attribute corresponds to the number of vertices in each community in the original graph, and the count edge attribute corresponds to the number of edges between communities in the original graph.

这篇关于在iGraph中绘制社区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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