Last week, the American Kennel Club announced the 2017 rankings of dog breed popularity in the USA. A few days later, Dominik Koch blogged about creating bump charts in R using ggplot2 to show changes in rank over time.
The ACK also released an update (a.k.a. pupdate) to the full list of breed rankings from 2013 to 2017, and it looked like a good dataset to try out the code for making bump charts.
For this post, I was only interested in the top ten breeds of 2017 and how they’ve changed in ranking since 2013.
In the original bump chart example with Olympic medal rankings, countries are labeled using little flags and the ggflags package. I wanted to use custom images as labels, and the ggimage package worked out great for that. I’ve written code to scrape and download dog photos by breed in the past, but for this post I drew each dog by hand.
Side note: I used this nifty function by Maëlle Salmon for batch resizing images using the packages purrr and magick. I uploaded all the drawings here.
Get the data
To import the rankings into R, I used Miles McBain’sdatapasta addin to smoothly copy and paste the first ten entries directly from a web browser to my source script in RStudio. The variable names for the different years needed some editing, but everything else stays as is.
To annotate the plots with my own dog drawings, I simply needed to add a variable containing the filenames that correspond to each breed. After that, wrangling the data into a long form suitable for making the bump chart was pretty easy thanks to various functions from dplyr and tidyr. The image files are in the working directory.
Customizing the plot appearance
I used the same custom theme as Dominik, which looks pretty good already.
Now we just need to change the labels and margins so that breed names and breed drawings appear as annotations on either side of the chart.
Final plot
This is what the final chart looks like.
A lot of the media coverage of the recent rankings noted how French bulldogs have increased in popularity significantly, and this visualization really shows it. Yorkies show the opposite pattern.
Thanks for reading. Feel free to contact me if anything isn’t working.
Cuteness aside, I’m aware of the health issues of brachycephalous breeds and I oppose selective inbreeding (line breeding) to meet arbitrary standards. Also: I’m very biased towards retrievers.