matnel
matnel

Reputation: 113

igraph using two layouts for different nodes

Is there a way to plot a graph using two different layouts, one for a set of nodes and another for all other nodes?

E.g., define that nodes 1-10 are plotted with circular layout and all other nodes are drawn with force-directed layout.

Upvotes: 0

Views: 367

Answers (1)

emilliman5
emilliman5

Reputation: 5956

Yes you can. You just need to hack together two different layouts.

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

Upvotes: 1

Related Questions