(igraph)基于属性的分组布局 [英] (igraph) Grouped layout based on attribute

查看:195
本文介绍了(igraph)基于属性的分组布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在R中使用iGraph包来布局网络图,并且我想根据属性值对顶点坐标进行分组.

I'm using the iGraph package in R to layout a network graph, and I would like to group the vertex coordinates based on attribute values.

类似于已回答的问题如何在igraph中进行分组布局?,我的问题不同在于,无需按从社区检测算法派生的社区成员对节点进行分组.

Similar to the answered question How to make grouped layout in igraph?, my question differs in that the nodes needn't be grouped by a community membership that was derived from a community detection algorithm.

相反,我想根据每个顶点预先知道的属性值使用组进行布局.

Rather, I want to layout with groups based on attribute values that are known in advance for each vertex.

例如,如果每个顶点都有一个属性"Master.Org",并且Master.Org有大约10到〜20个不同的值,那么我该如何布置图以使所有顶点都在同一Master.Org中被分组了吗?

For example, if each vertex has an attribute "Master.Org", and there are ~10 to ~20 distinct values for Master.Org, then how can I layout the graph such that all vertices within the same Master.Org are grouped ?

谢谢!

其他详细信息

实际上,两个单独的属性提供了嵌套的分组级别.

In fact, two separate attributes provide nested levels of grouping.

我的目标是布局一个图形对象,以使"Master.Org"和"Org.Of"值在图形上的XY坐标中分组在一起.

My goal is to layout a graph object such that the "Master.Org" and "Org.Of" values are grouped together in their XY coordinates on the graph.

例如,每个节点将属于一个"Org.Of".而且,"Master.Org"中可以有多个"Org.Of"值.

For example, each node will belong to an "Org.Of". And there can be multiple "Org.Of" values within the "Master.Org".

有何想法? 谢谢!

推荐答案

虽然这个问题比较老,但它是一个合理的问题,值得回答.

While this question is rather old, it is a reasonable question and deserves an answer.

未提供任何数据,因此我将生成一个任意示例.

No data was provided so I will generate an arbitrary example.

library(igraph)
set.seed(1234)
G = erdos.renyi.game(20, 0.25)
V(G)$Group1 = sample(3,20, replace=TRUE)
plot(G, vertex.color=rainbow(3, alpha=0.4)[V(G)$Group1])

不执行任何操作,将忽略该组.

Without doing anything, the Group is ignored.

现在,我们需要创建一个可以绘制节点的布局 在同一组中并拢.我们可以通过创建 具有相同节点但在两个节点之间具有其他链接的图 同一组中的节点.组内链接将被给出 权重较高,则原始链接的权重较小. 这将群集同一组中的节点.然后,我们将 布局以绘制原始图,而无需额外的链接. 他们只是为了获得良好的布局.

Now, we need to create a layout that will plot nodes in the same group close together. We can do this by creating a graph with the same nodes, but with additional links between nodes in the same group. The within-group links will be given a high weight and the original links will be given a small weight. This will cluster nodes in the same group. We then apply the layout to plotting the original graph, without the extra links. They were just to get a good layout.

G_Grouped = G
E(G_Grouped)$weight = 1

## Add edges with high weight between all nodes in the same group
for(i in unique(V(G)$Group1)) {
    GroupV = which(V(G)$Group1 == i)
    G_Grouped = add_edges(G_Grouped, combn(GroupV, 2), attr=list(weight=5))
} 

## Now create a layout based on G_Grouped
set.seed(567)
LO = layout_with_fr(G_Grouped)

## Use the layout to plot the original graph
plot(G, vertex.color=rainbow(3, alpha=0.4)[V(G)$Group1], layout=LO)

如果您想超出此范围以具有多个分组级别,则只需添加具有适当权重的其他链接即可连接子组.

If you want to go beyond this to have multiple levels of grouping, just add additional links with appropriate weights to connect the subgroups too.

这篇关于(igraph)基于属性的分组布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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