gganimate has transitioned to a state of release

Just to start of the year in a positive way, I’m happy to announce thatgganimate is now available on CRAN. This release is the result of a prettyfocused development starting in the spring 2018 prior to my useR keynote aboutit.

Some History

The gganimate package has been around for quite some time now with DavidRobinson making the first commitin early 2016. David’s vision of gganimate revolved around the idea offrame-as-an-aesthetic and this easy-to-grasp idea gave it an early success. Theversion developed by David never made it to CRAN, and as part of ramping downhis package development he asked me if I was interested in taking overmaintenance. I was initially reluctant because I wanted a completely differentAPI, but he insisted that he supported a complete rewrite. The last version ofgganimate as maintained by David is still availablebut I very quickly made some drastic changes:

While this commit was done in the autumn 2017, nothing further happened until Idecided to make gganimate the center of my useR 2018 keynote, at which point Iwas forced (by myself) to have some sort of package ready by the summer of 2018.

A fair amount of users have shown displeasure in the breaking changes thishistory has resulted in. Many blog posts have already been written focusing onthe old API, as well as code on numerous computers that will no longer work. Iunderstand this frustration, of course, but both me and David agreed that doingit this way was for the best in the end. I’m positive that the new API hasalready greatly exceeded the mind-share of the old API and given a year the oldAPI will be all but a distant memory…

The Grammar

Such drastic breaking changes were required because of a completely differentvision for how animation fitted into the grammar of graphics. Davids idea wasthat it was essentially a third dimension in the graphic and the animation wassimply flipping through slices along the third dimension in the same way as youwould look through the output of a CT scan. Me, on the other hand, wanted agrammar that existed in parallel to the grammar of graphics — not as part of it.

My useR keynote goes in to a lot of detail about my motivation and inspiration fortaking on this approach, and I’ll not rehash it in this release post. Feel freeto take a 1h break from reading as you watch the talk

The gist of it all is that animations are a multifaceted beast and requires muchmore than an additional aesthetic to be tamed. One of the cornerstones of thetalk is the separation of animations into scenes and segues. In short, a segueis an animated change in the underlying laws of the graphic (e.g. changes tocoordinate systems, scales, mappings, etc.), whereas a scene is a change inthe data on display. Scenes are concerned with what and segues are concernedwith how. This separation is important for several reasons: It gives me a naturalfocus area for the current version of gganimate (scenes), it serves as atheoretical backbone to group animation operation, and it is a central limit inanimation good practices: “You should never change how and what at the sametime”.

So, the version I’m presenting here is a grammar of animation uniquely focusedon scenes. This does not mean that I’ll never look into segues, but they areboth much harder, and less important than getting a scene grammar to make sense,so segues have to play second fiddle for now.

What’s in a scene

There are two main components to a scene: What we are looking at, and where weare looking from. The former is handled by transitions and shadows, whereasthe latter is handled by views. In brief:

  • transitions populates the frames of the animation with data, based on thedata assigned to each layer. Several different transitions exists thatinterpret the layer data differently.

  • shadows gives memory to each frame by letting each frame include data fromprior or future frames.

  • views allow you to modify the range of the positional scales (zoom andpan) either directly or as a function of the data assigned to the frame.

On top of these three main grammar components there is a range of functions tomodify how key parts of animations behave — for a general introduction to theins and outs of the API, please see the*Getting Started** guide.

Grammar vs API

While it may appear that grammar and API are the same, this is not the case. Agrammar is a theoretical construct, a backbone from which an API can be defined.Several APIs could implement the same grammar in multiple, incompatible, ways.For gganimate I have tried to align the API as much as possible with the ggplot2API, so that the line between the two packages becomes blurred. You change aplot to an animation by adding functions from gganimate to it, and the animationis rendered when printing the animation object in the same way as ggplots arerendered when printing the object. An example of this is addingtransition_reveal() to a plot to make it appear gradually along a numericvariable:

1
2
3
4
5
library(ggplot2)
library(gganimate)

ggplot(airquality) + 
 geom_line(aes(x = Day, y = Temp, group = Month))

1
2
last_plot() + 
 transition_reveal(Day)

For the most part, the marriage between the ggplot2 and gganimate APIs is a happyone, though it does show at points that the ggplot2 API was never designed withanimation in mind. I am particularly pleased with how powerful the API hasturned out, and I have already seen countless uses I had never anticipated.

The Future

While this release is a milestone for gganimate, it is not a signal of it beingdone as many things are still missing (even if we ignore the whole segue partof the grammar). It does signal a commitment to stability from now on, though soyou should feel confident in using this package without fearing that your codewill break in the future. You can follow the state of the package at itswebsite, , where I’ll also try to add additional guides andtutorials with time. If you create something with gganimate please share it ontwitter, as I’m eager to see what people will make of it.

I’ll do a sort-of live cookbook talk on gganimate at this years RStudio conf inAustin, so if you are there and interested to learn more about the package doswing by.

Now, Go Animate!

Related