Rotate persp3d plot and save images as png
data-visualization, r
Solution
Here is an alternative using the functions `spin3d` to change the view, and `movie3d` to save the images.
library(rgl)
x <- seq(-10, 10, length= 30)
y <- x
f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
z <- outer(x, y, f)
z[is.na(z)] <- 1
persp3d(x,y,z,theta=0,phi=25, col = "lightblue",
ticktype="detailed", xlab="", ylab="", zlab="",axes=FALSE)
movie3d(spin3d(axis = c(0,0,1), rpm = 10), duration=6, type = "png")
Note that by default `movie3d` saves the files in the folder set by `tempdir()`.
Problem
With R, I am using the `persp3d` function of the `rgl` package to get a nice 3d plot. Now I want to rotate the `persp3d` function and save each small rotated image as a png file. I want then to include the png in my latex presentation with the command `animategraphic`. I therefore want to aks, how I can do this? I need them in a way that I can implement them in latex, so the names of the png files should somehow be like a1,a2 and so on... My code to create the persp3d plot is: ``` persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=color[zcol2], ticktype="detailed", xlab="", ylab="", zlab="",axes=FALSE) ``` I then tried to spin it with the `spin3d` command: ``` spind3d(rpm=3) ``` which does not work. Also this would not save pngs to my drive?