Reputation: 2729
I am trying to replicate a figure from a text book with the igraph
package. This code draws the structure correctly:
library(igraph)
g <- graph( c( "W","X", "Y","Z", "Y","W", "Z","W"), dir=FALSE)
plot(g, vertex.shape = "none")
but the entire graphic is rotated so it does not match the book. The above plot has the X node up at 1:00 on the clock face. I would like it so it is out at 9:00. I saw a post that showed that igraph::tkplot() can be rotated but I need a static plot. Is there a way to rotate an igraph network plot that is not rendered with tkplot(g)?
Upvotes: 2
Views: 670
Reputation: 37661
Yes, you just need to control the layout. The default layout is done with layout_nicely
. To get that layout only rotated, just save the layout and multiply by a rotation matrix. You may need to play around a little with just how big a rotation to use.
LO = layout_nicely(g)
angle = 2*pi * 7.5/12
RotMat = matrix(c(cos(angle),sin(angle),-sin(angle), cos(angle)), ncol=2)
LO2 = LO %*% RotMat
plot(g, vertex.shape = "none", layout = LO2)
Upvotes: 3