My eye was caught by this tweet by Robin Wigglesworth of the Financial Times with an Alan Smith animation of the US Treasury yield curve from 2005 to 2009. It’s a nice graphic and it made me wonder what it would look like over a longer period.
The “yield curve” is the name given to the graphic showing the different annual rates paid on investors who in effect lend money to the US Treasury. In normal circumstances, investors who are prepared to make the loan on a long term basis demand higher effective interest rates as compensation for risk associated with inflation and future interest rates. When the situation goes in the other direction, and higher effective returns come from shorter term investments, it’s commonly seen as a sign of a coming recession. This isn’t because the “inverted yield curve” causes the recession, but because (amongst other things) it reflects investors’ fears that interest rates are about to be cut (in response to lower economic growth), hence best to lock in the return you can get now.
Anyway, here is my version of the animation, now with 29 years of daily data, streaming from You Tube (because it was too large to embed directly in my web page):
Alternatively, here’s a streamlined social-media-friendly version (as a GIF) that has monthly averages and scoots through a bit quicker.
I’m not sure these are great graphics. For one thing, with three frames for every day with data reported, the daily version is over 20,000 frames long and even at 25 frames per second that’s a pretty tedious thing to watch - 14.5 minutes in fact. More generally, it suffers from the common problems of animated statistical graphics:
- you have to be looking at just the right time to see the interesting things - like the yield inversion and other volatility in that 2006 to 2008 period
- some changes over time are actually less obvious to the viewer than if they could be presented on a single page.
In the original FT article, there’s a more focused animation by Smith, this one showing just the last 15 months, emphasising the yield inverstion at the end of that period. It’s quite effective in telling a very pointed story, rather than trying to show a long history in a single animation.
Animations aren’t always the best. In fact, it’s surely significant that I loathe video tutorials because I can’t flick my eye directly to the part I want but have to sit through the whole thing - even at high speed this is frustrating. Animations can have a similar problem.
For showing the longer history at a glance, consider this alternative presentation, still related to the animation’s visual structure. This has all 8,000 or so yield curves from those 29 years on a single static chart, each one drawn with 10% opacity to avoid colouring the page solid.
What I like about this version is that because it’s all there at once, you can make the comparisons across a broader period of time than is possible with the animation. You can see:
- The secular decrease in rates over this time period
- The period around 2005 when there were no 30 year rates for some reason
- The different yield inversions in context - showing as upwards swooshes in blue, green and yellow (for different periods) at the left of the graph
Plus it’s very pretty.
Finally, how about a much more traditional time series line chart. I actually find this the easiest to interpret of them all.
- The secular decrease is obvious again.
- The carefully chosen colours let you compare the different terms quite easily.
- This is the most dramatic depictiton of the way the shorter term yields hit the floor after 2008.
- Easiest chart of them all to interpret because of the familiar convention of the horizontal axis meaning time
- Still very pretty.
So what do I think?
Sometimes static graphs are beter than animations. Sometimes an old fashioned time series plot is better than less standard innovations. To make an animation tell a good story you often need more polishing, annotation and framing, not less.
More information on yield curves is easy to find on the Internet, and the piece in the Financial Times that Wigglesworth was referring to is worth a read. Here’s one of their very professional graphics:
One of the things that makes a difference to this, and to the animations in the same story, is the careful use of annotations to tell a story. That’s definitely what it takes to get a graphic to the next level, but it’s not something I’ve got time for right now.
Here’s the code for this (apart from that last one from the FT) - all pretty straightforward. Grabbing the data is easy with Wickham’s
rvest R package, and animations are so much easier than a few years ago thanks to Thomas Pedersen’s
gganimate. And let’s not forget the Viridis colours, originally developed for Python by Nathaniel Smith and Stefan van der Walt, and ported into an R package by Simon Garnier. In these graphics I use three variants of the Viridis colour schemes to represent different variables - the difference between long and short term yields at any one point in time, year, and the term of the yield. In each case, the variable I am trying to show is fundamentally ordered, and Viridis is at its best in showing that ordered nature in its colour.
|Hadley Wickham||15||assertthat, dplyr, forcats, ggplot2, gtable, haven, httr, lazyeval, modelr, plyr, rvest, scales, stringr, tidyr, tidyverse|
|R Core Team||11||base, compiler, datasets, graphics, grDevices, grid, methods, stats, tools, utils, nlme|
|Gábor Csárdi||4||cli, crayon, pkgconfig, progress|
|Kirill Müller||4||DBI, hms, pillar, tibble|
|Lionel Henry||4||purrr, rlang, svglite, tidyselect|
|Winston Chang||4||extrafont, extrafontdb, R6, Rttf2pt1|
|Yihui Xie||4||evaluate, knitr, rmarkdown, xfun|
|Jim Hester||3||glue, withr, readr|
|Thomas Lin Pedersen||3||farver, gganimate, tweenr|
|Yixuan Qiu||3||showtext, showtextdb, sysfonts|
|Dirk Eddelbuettel||2||digest, Rcpp|
|Jennifer Bryan||2||cellranger, readxl|
|Simon Urbanek||2||audio, Cairo|
|Stefan Milton Bache||1||magrittr|