r - 动画 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() 没有工作。
任何人都可以向我提供任何帮助吗?非常感谢 !
解决方案
很可能snapshot3d
不适合你。尝试使用选项webshot = FALSE
而不是默认的webshot = TRUE
. 它使用不同的机制来保存图像。
推荐阅读
- python - Python Pandas:如何将“resample”与“idxmin”一起使用?
- javascript - 为什么我的 redux 应用程序没有在 redux-thunk 中缓存异步 api 调用?
- python - 下载 S3 存储桶中子文件夹的全部内容
- reactjs - 不呈现 else 块的条件语句
- javascript - 推送 onClick 时过滤的项目不呈现(反应)
- javascript - 一次显示一个下拉菜单并关闭其他下拉菜单
- c# - 将数字拆分为列表/数组(例如 1998 到 1,9,9,8)
- javascript - 如何处理“阅读更多或更少”使用危险的SetInnerHTML加载内容
- android - CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera) 已过时
- python - 不确定 asyncio 的工作原理以及我如何从持续运行的异步文件夹看门狗函数返回信息