Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
570 views
in Technique[技术] by (71.8m points)

r - Using gganimate to export gif

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')

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

    gganimate(p, "output.gif")

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


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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

gganimate 1.0.6 and gifski 0.8.6

Based on the suggestion by @Ronak Shah, I've added an updated answer using anim_save() from the gganimate package - as it uses gifski now to render the .gif output.

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)

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...