Animated Graphs for data people

Let's get animated

This website is for people who do data analysis or statistics and want to make animated videos of their work. Because I use stop-frame animation, you are limited only by your imagination (and patience!), not by software. There are easier tools around, like gganimate in R, but they will limit your options. I use Stata and R here, but any software that lets you write a script/program to repeatedly make graphs and save them as picture files will do this. No fancy video editing or graphics software are involved!


0. First, install FFMPEG  ←you are here

1. Welcome

2. Line

3. Scatter

4. Phantom

5. Extended

What is FFMPEG?

FFMPEG is an open-source, free piece of software that is very widely used in the audio-visual world to convert digital content from one format to another. It usually sits in the background on your hard drive and gets "called" by other software to do the hard work behind the scenes. This is what we can do from Stata and R: once we have assembled all the individual frames we want for our animation, we will issue an order to FFMPEG to pull them all together into a video file. We can specify the size of the video (although it is better to do that when you save the graphs as image files, to keep the sharpest images), we can set the bitrate to balance better quality against a smaller video file, and we can choose the video format.

Let's take a closer look at an instruction sent from Stata to FFMPEG under Windows:

winexec "C:\Program Files\ffmpeg\bin\ffmpeg.exe" ///
-report -i "C:\animation\graph%d.png" -b:v 2048k ///
"C:\animation\new_video.mpg"

This command called winexec first looks up the FFMPEG executable file, then there are series of options which are passed to FFMPEG that tell it what you want it to do:

-report asks for a log file to be saved, which is handy in case things don't work out the way you expected

-i is followed by the input files (the images); here we have saved the graphs as graph0.png, graph1.png, graph2.png, and so on. That is what the %d tells FFMPEG to look for, and it will combine all those files into one video until it doesn't find the next graph in the sequaence of numbers (so make sure there are no breaks in the numbering)

-b:v means that you want the output to be a video

2048k means you want 2 megabit per second quality, which is reasonably pleasant to look at on screen

...then the instructions finish with the address and file name that you want to save.

The R code is very similar:

shell("C:\Program Files\ffmpeg\bin\ffmpeg.exe -report -i graph%d.png -b:v 2048k new_video.mpg",mustWork=FALSE)

FFMPEG works out from the file extensions (in this case, .png and .mpg) what input and output formats you want to use.

How do I get it?

Head over to the FFMPEG Download pages which will point you in the right direction. If you have Linux or Mac, you might already have FFMPEG installed. If you don't have administrator privileges to save in a Program Files or Applications folder, you can run FFMPEG from anywhere, even a memory stick, you just have to point your data analysis software to the right place.