繁体   English   中英

动画3D散点图并保存为gif在R

[英]Animated 3D scatterplot and save it as gif in R

我想要 plot 动画 3D 散点图并将其另存为 gif。 我遵循了 R 图库示例提供的代码: 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 成功 output a 3d 散点图 plot. Static 3d 散点图 plot

但是最后的 output: 3dAnimatedScatterplot.gif,只是一个黑色的图像3dAnimatedScatterplot.gif

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

任何人都可以为我提供帮助吗? 多谢 !

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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