Using gganimate to export gif

后端 未结 2 621
不知归路
不知归路 2020-12-18 22:25

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

    library(ggplot2)
    #devtools::install_github(\'thomasp85/gganimate\')
    librar         


        
相关标签:
2条回答
  • 2020-12-18 23:01

    You can do like this:

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

    0 讨论(0)
  • 2020-12-18 23:08

    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)
    

    0 讨论(0)
提交回复
热议问题