Using gganimate to export gif

You can do like this:

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

enter image description here


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