将更多节点添加到“星形”布局的中心-igraph

问题描述 投票:0回答:1

我想创建一个网络图,该网络图的中间将有2个节点,其余的节点将其包围。边缘从节点“ A”和“ B”到其余节点,但它们彼此不连接。

[我发现igraph包中的布局“星形”可能最适合我。从理论上讲,可以在“星形” (manual page)的中心添加更多的节点,但是对我来说不起作用,因为无论在center参数中指定两个节点还是只有一个。

#data
set.seed(1)
name <- LETTERS

a <- data.frame(from = "A", to = name)
b <- data.frame(from = "B", to = name)

sample <- rbind(a,b)
sample <- sample[-c(1,2,27,28), ] #please note removed edges between A-A, A-B, B-B, and B-A

#plot
g <- graph_from_data_frame(sample)
plot(g, layout = layout_as_star(g, center = V(g)[c("A", "B")]) )

enter image description here

r visualization igraph
1个回答
0
投票

我不认为layout_as_star允许多个中心。您仅参考的帮助页面上的center参数允许您指定哪个节点为中心,而不是多个中心。因此,要获得想要的东西,您需要做更多的事情布置自己。这是一种以以下形式获取图形的方法:你自找的。我用layout_as_star布置所有节点除了其中一个中心。但是我们不希望两个“中心”在圆的正中心,否则它们会重叠。所以我移动中心并为第二个“中心”定位。

library(igraph)

s1 = make_star(25, mode="out")
V(s1)$name = LETTERS[-2]

s2 = make_star(25, mode="out")
V(s2)$name = LETTERS[-1]

LO1 = layout_as_star(s1)

TwoCenters = union(s1, s2)

LO2 = LO1
LO2[1,] = c(-0.2, 0)
LO2 = rbind(LO2, c(0.2,0))

plot(TwoCenters, layout= LO2)

Star with Two Centers

© www.soinside.com 2019 - 2024. All rights reserved.