首页 > 解决方案 > 动画 3D 散点图并将其保存为 R 中的 gif

问题描述

我想绘制一个动画 3D 散点图并将其保存为 gif。我遵循了 R Graph Gallery 示例提供的代码: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 成功输出 3d 散点图。 静态 3d 散点图

但最终输出:3dAnimatedScatterplot.gif,只是一个黑色图像 3dAnimatedScatterplot.gif

当我设置时clean=F,所有帧图像都是黑色的。所以,我猜 play3d() 没有工作。

任何人都可以向我提供任何帮助吗?非常感谢 !

标签: ranimation3drgl

解决方案


很可能snapshot3d不适合你。尝试使用选项webshot = FALSE而不是默认的webshot = TRUE. 它使用不同的机制来保存图像。


推荐阅读