Flo*_*Flo 10 r ggplot2 gganimate
该包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')
Run Code Online (Sandbox Code Playgroud)
现在如何导出这个gif?在之前(现已存档)的版本中,gganimate这很简单:
gganimate(p, "output.gif")
Run Code Online (Sandbox Code Playgroud)
但是,我在当前gganimate包中找不到等效函数.
注意:这个问题似乎与我从中获取MWE代码的问题完全重复.但是,gganimate已更新并在新版本中,在查看器窗格中显示动画与导出它似乎是不同的问题.
EJJ*_*EJJ 12
根据@Ronak Shah 的建议,我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)
Run Code Online (Sandbox Code Playgroud)
您可以这样:
anim <- animate(p)
magick::image_write(anim, path="myanimation.gif")
Run Code Online (Sandbox Code Playgroud)