igraph使用两个布局为不同的节点

时间:2017-08-03 08:16:19

标签: r igraph

有没有办法使用两种不同的布局绘制图形,一种用于一组节点,另一种用于所有其他节点?

,例如,定义节点1-10用圆形布局绘制,所有其他节点用力导向布局绘制。

1 个答案:

答案 0 :(得分:1)

是的,你可以。你只需要将两种不同的布局混合在一起。

library(igraph)

gr <- random.graph.game(100, p.or.m = 0.25, type = "gnp")

lay1 <- layout_in_circle(induced_subgraph(gr, 1:20)) ##layouts are just matrices with x, y coordinates
lay2 <- layout_with_fr(induced_subgraph(gr, 21:100)) #I used Fruchterman-Reingold on the subgraph excluding the nodes in the circle but you could include them and then overwrite their layout coordinates with the coordinates for the circle
lay3 <- rbind(lay1+2, lay2) ## I added a scalar to shift the circlular nodes out of the middle of the force-directed layout to make it more obvious.
plot(gr, layout=lay3, vertex.size=8)

enter image description here