包gganimate创建gifs (来自这里的MWE代码):
library(ggplot2)
#devtools::install_github('thomasp85/gganimate')
library(gganimate)
p <- ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot() +
# Here comes the gganimate code
transition_states(
gear,
transition_length = 2,
state_length = 1
) +
enter_fade() +
exit_shrink() +
ease_aes('sine-in-out')现在怎么出口这个gif呢?在以前的(现在存档的) gganimate版本中,这很简单:
gganimate(p, "output.gif")但是,我无法在当前的gganimate包中找到一个等价的函数。
注意:这个问题似乎完全重复了我为MWE编写代码的问题。但是,gganimate已经更新,在新版本中,在查看器窗格中显示动画与导出动画似乎是不同的问题。
发布于 2018-07-20 11:42:05
你可以这样做:
anim <- animate(p)
magick::image_write(anim, path="myanimation.gif")

发布于 2020-08-04 15:36:57
gganimate 1.0.6和gifski 0.8.6
根据@Ronak的建议,我使用anim_save()从gganimate包中添加了一个更新的答案--因为它使用gifski 现在来呈现.gif输出。
library(ggplot2)
library(gganimate)
# install.package("gifski") #if not already installed
p <- ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot() +
transition_states(
gear,
transition_length = 2,
state_length = 1
) +
enter_fade() +
exit_shrink() +
ease_aes('sine-in-out')
anim_save("filenamehere.gif", p)

https://stackoverflow.com/questions/51440496
复制相似问题