2017-08-03 156 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