简体   繁体   English

如何在igraph(R)中进行同心圆布局

[英]how to make concentric circles layout in igraph (R)

I'm trying to create a special graph layout where 2 different types of nodes (based on their attribute) are placed on 2 different circles with different radius (concentric circles layout). 我正在尝试创建一种特殊的图形布局,其中将2种不同类型的节点(基于其属性)放置在具有不同半径的2个不同圆上(同心圆布局)。

Here's a toy example where a graph with 10 nodes have an attribute (size). 这是一个玩具示例,其中具有10个节点的图具有属性(大小)。 The goal is to place the nodes with size less than 5 on an inner circle, and the nodes with size greater than 5 on an outer circle: 目标是将尺寸小于5的节点放在一个内圆上,将尺寸大于5的节点放在一个外圆上:

g <- make_full_graph(10)
V(g)$size = V(g)

I couldn't find any such layout supported by igraph library. 我找不到igraph库支持的任何此类布局。 Does anyone know how to achieve this? 有谁知道如何实现这一目标?

There is the layout_in_circle option if you only wanted one circle. 如果只需要一个圆,则有layout_in_circle选项。 You could apply that separately to each of your groups with something like this 您可以使用类似的方法将其分别应用于每个组

layout_in_circles <- function(g, group=1) {
    layout <- lapply(split(V(g), group), function(x) {
        layout_in_circle(induced_subgraph(g,x))
    })
    layout <- Map(`*`, layout, seq_along(layout))
    x <- matrix(0, nrow=vcount(g), ncol=2)
    split(x, group) <- layout
    x
}

Then you could plot with 然后你可以用

plot(g, layout=layout_in_circles(g, group=V(g)>5))

It doesn't do anything special to try to make the edges pretty. 尝试使边缘更漂亮并没有什么特别的事情。 But I guess the point is you can define whatever function you want to control the layout by returning a matrix of coordinates. 但是我想关键是您可以通过返回坐标矩阵来定义要控制布局的任何函数。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM