Animation using magick and ´gganimate´

See lecture notes about animation and more importantly the answer to the lab.

Low-level approach - magick

Approach to draw every frame of the animation. More work but also more control.

Basic steps to produce animation:

  • Assign value (fx. img) to call of magick::image_graph to open a magick graphics device
  • Run a loop that draws each frame of the animation
  • Call dev.off() to close the magick graphics device
  • Run image_animate(img)

High-level approach - gganimate

NOTE! Install package gifski. If installed, gganimate will make sure to use that as the backend when creating the GIFs

See the getting started article as well as run examples in references section of each transition_... function.

Create animation “superimposed” onto static image

See example how to do this in this model answer

Misc notes about gganimate

  • If using exit/enter_xx function you NEED to specify a grouping aesthetic EXPLICITLY, which will devide data into subsets that the transitions will display in each frame.
  • To slow down the animation, assign it a value p, and then use animate(p, fps = 1) fx. to control the frames pr. second.
Back to top