使用gganimate导出gif [英] Using gganimate to export gif

查看:175
本文介绍了使用gganimate导出gif的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gganimate创建gif(来自此处的MWE代码):

The package gganimate creates gifs (MWE code from here):

    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的先前版本(现已存档)中,这很简单:

How can export this gif now? In the previous (now archived) version of gganimate this was simple:

    gganimate(p, "output.gif")

但是,我在当前的gganimate程序包中找不到等效的函数.

However, I could not find an equivalent function in the current gganimate package.

注意:这个问题似乎与我从中获取MWE代码的问题完全相同.但是,gganimate已更新,并且在新版本中,在查看器窗格中显示动画与导出动画似乎是不同的问题.

Note: This question seems like an exact duplicated of the question from which I took the code for the MWE. However, gganimate has been updated and in the new version, displaying an animation in the viewer pane vs. exporting it seem to be different issues.

推荐答案

您可以这样做:

anim <- animate(p)
magick::image_write(anim, path="myanimation.gif")

这篇关于使用gganimate导出gif的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆