【发布时间】:2018-12-28 15:28:57
【问题描述】:
gganimate 包创建 gif(来自here 的 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 已更新,在新版本中,在查看器窗格中显示动画与导出动画似乎是不同的问题。
【问题讨论】:
-
您是否尝试过使用
image_write()? -
有一个
animate函数。 -
@Miha。以前不是,但是当我尝试时,我注意到
p不是魔法图像对象,我不确定如何将其转换为一个。 @Axeman,我做到了,但不知道如何按照file="p.gif" -
@Miha,我愿意,因此包中的错误:
Error: The 'image' argument is not a magick image object.。也许我做错了什么?你将如何使用magick将 p 导出为 gif? -
image_graph和dev.off()应该可以工作。或者另一种选择:使用image_animate和image_write。所以试试save.gif <- image_animate(p, fps = 2); image_write(save.gif, "output.gif")