Extended example 1: missing data lecture

The animation below is one I developed for a lecture on missing data. The idea is that you have 15 observations with missing data, and they move to their true (but unknown) positions among the jittered dot plot on the y-axis. It uses the phantom data approach to create trails, but adds in some more features:

  • At the beginning there is text saying "15 missing" which then fades out as the markers for the 15 observations fade in.
  • The "missing data" markers are hollow circles (pch=1 in R) so when they start moving, the dark color of the trail fills in the hollow centre. To keep the hollow look, you need to superimpose a second copy of each data point that is a white solid circle with a slightly smaller radius. You'll note that the effect is not perfect when they overlap, so it could be tweaked further.
  • When the markers stop moving, there is a new loop that allows the trails to catch up with them and fade away.
  • I wanted to be able to pause the video and talk about the markers at the start and finish locations, so I left a few seconds of identical frames at each end. In the R code you will see I did this by looping and drawing the same plot many times. You might feel this is an ugly and inefficient way to do it, and indeed you would be well advised to use shell commands to copy the file rather than this approach, but it does have the benefit that the code comprises a series of loops in chronological order so it is easy to see what it is doing.

Click here for the R code.

Extended example 2: Booze Space

This is a video I did for an article in Significance magazine. Two time series (sales of beer and wine in the UK) are plotted to the x and y axes so that over time we move around in booze space. There are a number of additional features here:

  • You provide the duration in seconds at the start and R works out how many interpolated frames are needed
  • Interpolation is by cubic splines to get a smooth effect
  • Raster images are displayed (the Union flag and the holly leaves)
  • A "clock" turns round at the top, made up of an ellipse and an arrow

It's worth noting how I make extra effort to write code that will work with different datasets. This is more work, but it means that I can just copy it across into future animations, building them up from bits of previous ones. The only place in the code where I failed to do this (hey, it was getting late and I had a deadline!) was the coloured lines in the outro section, whose co-ordinates are hard-wired in.

Click here for the R code.

Extended example 3: Animated Ant!

Yes, the most hard-working member of the animatedgraphs.co.uk team was constructed one afternoon using this R code. The pie chart is drawn as polygons so that one of them can move off, and the antennae and legs have some sort of sinusoidal motion. Apart from that, it just brings together aspects explored previously.