简体   繁体   中英

How to rotate a plotted igraph, given a specific layout (r code)?

I have the following code:

require(igraph)
g = make_star(8, mode="undirected", center=1)
layout.old = layout_with_fr(g, dim=3)
plot(g, layout = layout.old)

I'd like to plot the same graph but with a rotation of degree a for any a wrt the original layout, wrt a fixed axis, no matter what it is. The idea is to construct a step-wise animation, so I need to plot a new graph (using the function 'plot') for each step (each step gives the same graph, but rotated).

How to do that?

Thanks so much in advance!

You can do it using the rgl::rotate3d function. For example to rotate by 10, 20, ..., 100 degrees about the axis in direction (x,y,z) = (1,1,1) use

for (a in 10*(1:10)) {
   plot(g, layout = rgl::rotate3d(layout.old, a*pi/180, x=1,y=1,z=1))
   Sys.sleep(1)
}
  

You could also use rglplot(g, layout = layout.old) for an interactive plot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM