我使用了三个向量x
、y
、z
,每个向量的长度都是N(假设N是一个较大的自然数,比如20000)。为了可视化这一点,我可以使用以下R代码轻松地绘制该代码:
library("plot3D")
lines3D(x, y, z, type = "l")
现在,我在想,如果我们可以用向量x
,y
,z
制作一个小的三维动画(即3D GIF)。在R中有可能吗?
注意:我以前在R中做过2D GIF,在ggplot2
、gganimate
、magick
等软件包的帮助下。但是,我很好奇对于3D数据是否可以做同样的事情。提前谢谢。
发布于 2021-04-24 08:15:09
使用.gif包创建animation
非常简单(请注意,它需要运行“ImageMagick”或“GraphicsMagick”)。安装之后,您可以这样做(我假设您希望以不同的角度显示您的情节):
library(plot3D)
library(animation)
x <- runif(1000)
y <- x*2+runif(1000)
z <- sample(1:10,length(x),replace = T)*x/y
ani.options(interval=0.5,nmax=35)
saveGIF(for(t in seq(0,360,10)){
lines3D(x, y, z, type = "l",theta=t)
}, movie.name = "animation.gif")
https://stackoverflow.com/questions/67236151
复制相似问题