可视化将网络划分为社区的结果 [英] Visualizing the result of dividing the network into communities

查看:76
本文介绍了可视化将网络划分为社区的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据集包括网络矩阵和属性数据框. 网络数据集本身具有3个数据集,我只想处理 PrinFull 数据集,也只需要处理PRIN属性数据.我的数据在下面的两个链接中上传. 我在数据集上添加了所有属性.

The dataset is included the network matrix and attribute data frame. Network dataset has 3 data set itself, that I just want to work on PrinFull dataset and also just PRIN attribute data. my data is uploaded in this two link below. I added all attribute on my data set.

https://drive.google.com/file/d /1MZCdeAZF0joIQLwVeoVXmKpf7r8IJ2wq/view?usp = sharing

https://drive.google.com/file/d/1MZCdeAZF0joIQLwVeoVXmKpf7r8IJ2wq/view?usp=sharing https://drive.google.com/file/d/1I96BAUo8TjJMWCWpn_SIhp54snfZ0Bd5/view?usp=sharing I want to plot my community detection algorithm, the code is as below , but my plot is messy and not understandable. how can I plot in a better way? can anyone help me?

load('/content/CISPRINWOSmatrices.RData')
load('/content/CISPRINWOS_attributes.RData')

library("igraphdata")
library("igraph")
library("network")
library("statnet")
library("intergraph")
library("dplyr")
library("stringr")
library("RColorBrewer")
library("sand")




nodePRIN <- data.frame(PRIN)
#nodePRIN
relationsp <- as.matrix(PrinFull)

PRIN_graph = graph_from_adjacency_matrix(relationsp, mode="undirected",weighted = TRUE)
PRIN_graph

# Girvan-newman algorithm
gn.comm <- cluster_edge_betweenness(PRIN_graph)

#How many communities?

unique(gn.comm$membership)

#attach community labels as vertex attribute
V(PRIN_graph)$GN.cluster <- membership(gn.comm)
PRIN_graph

V(PRIN_graph)$Author[V(PRIN_graph)$GN.cluster==69]
# visualizing the result of dividing the network into communities

par(mar=c(0,0,0,0))

colors <- rainbow(max(membership(gn.comm)))
plot(gn.comm, PRIN_graph, vertex.size = 6, 
vertex.color=colors[membership(gn.comm)], vertex.label = NA, edge.width = 1)

[![enter image description here][1]][1]







推荐答案

您无能为力,很容易看到带有9379个链接的2839个节点. 屏幕上没有太多空间.不过,我有一些建议 不仅可以将图形传递到绘图中,还可以提供更多见识.

Nothing that you can do will make it easy to see 2839 nodes with 9379 links. There just isn't that much space on the screen. Nevertheless, I have some suggestions that may provide more insight than just passing the graph into plot.

首先,快速浏览一下您的图,发现该图不是由单个图组成的 连接的组件.

First, a quick glance at your plot reveals that this graph is not composed of a single connected component.

COMP = components(PRIN_graph)
table(COMP$membership)
   1    2    3    4    5    6    7    8    9   10   11   12   13   14   
2696   42    2    4   18   13    2    7    7    2    3    2    2    2   
  15   16   17   18   19    20   21   22   23   24   25   26   27 
   2    6   14    3    1     1    1    2    1    3    1    1    1 

因此2696个节点在一个大型组件中,其余143个 包含26个小组件.大组件中的2696个节点不知所措 较小的组件和26个较小的组件会造成视觉混乱 对于大组件.让我们分离26个小组件.

So 2696 of the nodes are in a single large component and the remaining 143 are in 26 small components. The 2696 nodes in the big component overwhelm the smaller components and the 26 small components acts as visual clutter for the big component. Let's separate the 26 small components.

SC = which(COMP$membership != 1)
SmallComps = induced_subgraph(PRIN_graph, SC)

现在很容易看到所有这些小组件的社区结构.

Now it is easy to see the community structure on all of these small components.

SC.gn.comm <- cluster_edge_betweenness(SmallComps)
colors <- rainbow(max(membership(SC.gn.comm)))
plot(SC.gn.comm, SmallComps, vertex.size = 6, 
    vertex.color=colors[membership(SC.gn.comm)], 
    vertex.label = NA, edge.width = 1)

通常,很小的部分由一个社区组成, 尽管有一些结构.

Mostly, small components comprised of a single community, although there are a few with some structure.

那是容易的部分,现在让我们看一下重要的组成部分.

That was the easy part, now let's look at the big component.

LC = which(COMP$membership == 1)
LargeComp = induced_subgraph(PRIN_graph, LC)

Girvan-Newman在这个庞大的区域内产生了43个社区

Girvan-Newman produces 43 communities within this large component

LC.gn.comm <- cluster_edge_betweenness(LargeComp)
max(LC.gn.comm$membership)
[1] 43

但是简单地绘制,仍然会造成混乱.

But simply plotting that still leaves a mess.

par(mar=c(0,0,0,0))
colors <- rainbow(max(membership(LC.gn.comm)))
set.seed(1234)
plot(LC.gn.comm, LargeComp, vertex.size = 6, 
    vertex.color=colors[membership(LC.gn.comm)], 
    vertex.label = NA, edge.width = 1)

我将建议两种方法来改善此图的外观:
分离社区并与社区签约.

I will suggest two ways to improve the appearance of this graph:
separating the communities and contracting the communities.

分隔社区

基于此先前的答案, 我们可以将顶点放置在相同的社区组中,并进行不同的处理 社区保持更远的距离.

Based on this previous answer, we can position vertices in the same community group together and make different communities stay further apart.

LC_Grouped = LargeComp
E(LC_Grouped)$weight = 1
for(i in unique(membership(LC.gn.comm))) {
    GroupV = which(membership(LC.gn.comm) == i)
    LC_Grouped = add_edges(LC_Grouped, combn(GroupV, 2), attr=list(weight=6))
} 

set.seed(1234)
LO = layout_with_fr(LC_Grouped)
colors <- rainbow(max(membership(LC.gn.comm)))
par(mar=c(0,0,0,0))
plot(LC.gn.comm, LargeComp, layout=LO,
    vertex.size = 6, 
    vertex.color=colors[membership(LC.gn.comm)], 
    vertex.label = NA, edge.width = 1)

这可以使社区脱颖而出,但是仍然很难 看看关系.所以另一种选择是

This makes the communities stand out better, but it is still pretty hard to see the relationships. So another option is

与社区签订合同

只需为每个社区绘制一个节点.在这里,我将每个区域 社区顶点与该社区的成员数量成正比 然后我根据顶点的角度对它们进行了粗略的分组.

Just plot a single node for each community. Here, I make the area of each community vertex proportional to the number of members of that community and I colored the vertices using a coarse grouping based on their degrees.

GN.Comm = simplify(contract(LargeComp, membership(LC.gn.comm)))
D = unname(degree(GN.Comm))

set.seed(1234)
par(mar=c(0,0,0,0))
plot(GN.Comm, vertex.size=sqrt(sizes(LC.gn.comm)),
    vertex.label=1:43, vertex.cex = 0.8,
    vertex.color=round(log(D))+1)

您可以看到有些社区几乎没有与其他社区建立连接,有些则是 很好的联系.这些可视化都不是完美的,但我希望它们可以对结构和关系提供一些见识.

You can see that some communities barely connect to any others and some are very well connected. None of these visualizations are perfect, but I hope that they might provide some insight into the structure and relationships.

这篇关于可视化将网络划分为社区的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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