2017-08-03 35 views
0

有没有办法用两种不同的布局来绘制图形,一种是针对一组节点,另一种针对所有其他节点?igraph为不同节点使用两种布局

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

回答

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