A cheatsheet on the gganimate library.
transition_(): What variable controlsview_(): Should the axes change with theenter/exit_(): How does new data getshadow_(): Should previous data beease_aes(): How do you want to handle thetransition_() orview_() to make an animation. The otherlibrary(tidyverse)library(gganimate)a <- ggplot(diamonds, aes(carat, price)) + geom_point()b <- ggplot(txhousing, aes(month, sales)) + geom_col()c <- ggplot(economics, aes(date, psavert)) + geom_line()enter/exit_*() functions can be combined so that you can have old data fade away andexit_fade() and exit_shrink() to the plot
transition_manual(): Similar to transition_states(), but without intermediate states.transition_layers(): Add layers (geoms) one at time.transition_components(): Transition elements independently from each other.transition_events(): Each element’s duration can be controlled individually.
anim_a <- a + transition_states(color, transition_length = 3, state_length = 1)
animation_to_save <- anim_a + exit_shrink()anim_save("first_saved_animation.gif", animation = animation_to_save)Since the animation argument uses your last rendered animation by default, this also works:
anim_save("second_saved_animation.gif")
anim_save() uses gifski to render the animation as a .gif file by default. You can use the renderer
argument for other output types including video files (av_renderer() or ffmeg_renderer()) or
spritesheets (sprite_renderer()):
# requires you to have the av package installed
anim_save("third_saved_animation.mp4",renderer = av_renderer())`view_zoom()view_zoom() works similarly toview_step(), except it changes the view byview_step() and view_zoom() haveview_*_manual() versions for setting viewsview_zoom()view_zoom() works similarly toview_step(), except it changes the view byview_step() and view_zoom() haveview_*_manual() versions for setting viewsNo comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.