IN THIS POST WE’RE GOING to make an animated version of the famous Federal Reserve dot plot comparing the dots in March 2016 to June 2016. As far as celebrity charts go, the dot plot has to be up there. Check out how much “dot plot” has grown in search popularity since the Fed introduced their dot plot in 2012:
Ultimately, it will look something like this:
The dot plot is a special chart that shows the distribution of expectations of the Federal Open Market Committee (FOMC) for the federal funds rate. Specifically it captures the views of each individual FOMC member for the following:
Each shaded circle indicates the value (rounded to the nearest 1/8 percentage point) of an individual participant’s judgment of the midpoint of the appropriate target range for the federal funds rate or the appropriate target level for the federal funds rate at the end of the specified calendar year or over the longer run.
The Fed makes the dot plot information available in a handy format here: FOMC materials. For example, the June 2016 projections look like this:
I’ve tidied the data (in Excel) so that it has three columns. One corresponding to the rate (rate), one corresponding to the horizon (x), and one corresponding to the count of dots (count). It looks like:
We’re going to begin with two text files capturing (tidied) tables for March 2016 and June 2016. With these two files in hand our R dataviz party can get started.
Making the dots
We’ll be using ggplot2, which has a plot type called geom_dotplot, but unfortunately this plot doesn’t work very well for what we want to do. Perhaps parameters could be set to make the image we want, but I’m going to build the plot myself. This follows a pattern similar to what we did with the distribution plots for unemployment in an earlier post.
First we’ll set up our libraries:
Next we’re going to find the location for each dot in the dot plot. This requires some simple math. We’re going to set the dots along a line between +/-0.4 from the index value for each entry on the x axis (1 for 2016, 2 for 2017, 3 for 2018 and 4 for Longer Run). If there is an odd number of dots, we’ll being at the index value and add two dots +/- a fixed amount of spacing the interval. The interval will be determined by the maximum number of dots along any row. For an even number of dots, we’ll set the first two dots at +/- the interval.
Turns out for this example, we can set the interval to 0.2. This seems to work with the number of dots we have, but isn’t a general solution. For different data you might need to tune the interval.
Now make a static plot:
Animating the dots
Now we’re ready to animate. For more explicit discussion, see my earlier post. What we’re going to do is load each month worth of dots and then then use tweenr to interpolate between the points.
A dot goes missing
The way I’m using tweenr, with the tween_states function, I need each dataset to have the same number of observations (rows). This normally wouldn’t be a problem as there are usually 17 dots corresponding to each FOMC member. But in June 2016 one dot went missing. There were only 16 dots for the “Longer Run” dot.
It turns out that James Bullard from the St. Louis Fed claimed the missing dot, and even wrote a short paper on why he didn’t think the “Longer Run” dot was useful. You can read more about it here.
In order to deal with the missing dot and have the animation work, we’re going to need to pad the data frame with the June dots. I chose to do it by adding a large positive value (8) outside the range of the plot. This will result in the dot flying off the top of the chart in the animation. I imagine a tiny voice say “forget this I’m outta here!”
Running this code should create our animated dot plot: