简体   繁体   中英

Animated 3D scatterplot and save it as gif in R

I want to plot a animated 3D scatterplot and save it as gif. I followed the code provided by the R Graph Gallery example: https://www.r-graph-gallery.com/3-r-animated-cube.html .

library(rgl)
library(magick)
options(rgl.printRglwidget = TRUE)

# Let's use the iris dataset
# iris

# This is ugly
colors <- c("royalblue1", "darkcyan", "oldlace")
iris$color <- colors[ as.numeric( as.factor(iris$Species) ) ]

# Static chart
plot3d( iris[,1], iris[,2], iris[,3], col = iris$color, type = "s", radius = .2 )

# We can indicate the axis and the rotation velocity
play3d( spin3d( axis = c(0, 0, 1), rpm = 20,dev = cur3d()),startTime = 0, duration = 10 )
# Save like gif
movie3d(
  movie="3dAnimatedScatterplot", 
  spin3d( axis = c(0, 0, 1), rpm = 20,dev = cur3d()),
  startTime = 0,
  duration = 10, 
  dir = ".",
  type = "gif", 
  clean = T,
  fps=10,
  convert=T
)

plot3d was successed output a 3d scatter plot. Static 3d scatter plot

But the final output: 3dAnimatedScatterplot.gif,just a black image 3dAnimatedScatterplot.gif

when I set clean=F , all frame images are black. So, I guess the play3d() was not working.

Can anyone provide any help to me? Thanks a lot !

Most likely snapshot3d isn't working for you. Try it with the option webshot = FALSE instead of the default webshot = TRUE . That uses a different mechanism for saving the image.

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