我不相信有专门的布局可以做到这一点,但您可以通过创建一组布局坐标然后按您的权重缩放它们以非常简单的方式实现此效果。
R 中的示例代码如下:
library(igraph)
# toy data
d = data.frame("n1"=c('A','A','A','A'), "n2"=c('B','C','D','E'), "weight"=c(1,1.5,2,5))
g <- graph_from_data_frame(d)
# we can create a layout object that is just coordinate positions
coords <- layout_(g, as_star())
coords
#> [,1] [,2]
#> [1,] 0.000000e+00 0.000000e+00
#> [2,] 1.000000e+00 0.000000e+00
#> [3,] 6.123234e-17 1.000000e+00
#> [4,] -1.000000e+00 1.224647e-16
#> [5,] -1.836970e-16 -1.000000e+00
# Knowing this is a star the N nodes should have N-1 edges. We can scale
# The N-1 positions by the weights
weight.scale <- c(1, d$weight)
coords2 <- weight.scale * coords
coords2
#> [,1] [,2]
#> [1,] 0.000000e+00 0.000000e+00
#> [2,] 1.000000e+00 0.000000e+00
#> [3,] 9.184851e-17 1.500000e+00
#> [4,] -2.000000e+00 2.449294e-16
#> [5,] -9.184851e-16 -5.000000e+00
# we can inspect
plot(g, layout = coords2)
由reprex package (v0.2.1) 于 2019 年 2 月 7 日创建