Are waffle charts an improvement on pie charts?


Hey folks,

Long time friends of Riffomonas know that I’ve been teaching data science classes for close to 20 years. The hallmark of my teaching has been three-day workshops where I either teach R (here and here) or the mothur software package. I’ve gotten feedback that three days is just too much time for people to carve out of their busy schedules. So, I’m excited to be offering a 1-day (6 hours) data visualization workshop on May 9th. This will cover an introduction to the ggplot2 package.

My goal is to help you develop that mental model so that you can leave the workshop understanding the ggplot2 framework and add to your understanding of the model as you go off on your own journey learning more advanced topics. You can learn more and register by clicking the button below. Feel free to email me if you have any questions.

If a full day is still too much time, let me know. I could schedule a 6-hour workshop over two days. I can also make an even shorter workshop!


I’m sorry, not sorry, for all the plots I share from the New York Times. The reality is that they’re about the best in data journalism. What they don’t give away for free is often available through our universities’ academic subscriptions. If you know of another source of great, consistent, data journalism, please send it my way.

In the US there has been a lot of discussion about the federal budget. Cuts to NIH, NSF, CDC, and everything else seems to be about shoring up the budget to remove $1,000,000,000,000 - $1 trillion - from an $8.3 trillion budget (this doesn’t include interest on the debt). The NYT has been using “waffle charts” to depict the budget in their reporting. Here’s an example from an April 13th article in the UpShot titled, “Why Elon Musk Hasn’t Come Close to Finding $1 Trillion in Cuts”.

My impression has been that going after the NIH and NSF has been like trying to find $100 by searching for lost coins in my couch. Throughout the article they provide a series of aggregated waffle charts to show what different types of cuts might look like. I can imagine another article with an interactive visualization that would allow the user to find the $1 trillion.

A waffle chart is also called a “square pie chart”. That’s fair. Each square represents a consistent value. In this case, it’s $5 billion. One problem with pie charts is that it’s really difficult to interpret the relative area of a wedge from a circle. In contrast, a waffle chart deals in squares, which can be counted to make comparisons between groups easier. What do you think of this alternative?

Anyway, how would we make this in R? One thought would be that these are effectively heat maps with a few specific fill colors for each group. It would take some logic to figure out how to make specific tiles in the heat map the same group and preferably to have those tiles be arranged next to each other. Thankfully, there’s a package for that {waffle}.

Looking through the {waffle} package’s GitHub documentation, I see a lot to like. Instead of squares, you could also use icons like pizza pieces, slices of bread, or apples. You can also compile multiple waffle charts with facet_wrap() or iron(). Here’s an example that I would riff off of to recreate the NYT waffle chart:


library(hrbrthemes)
library(waffle)
library(tidyverse)
tibble(
  parts = factor(rep(month.abb[1:3], 3), levels=month.abb[1:3]),
  values = c(10, 20, 30, 6, 14, 40, 30, 20, 10),
  fct = c(rep("Thing 1", 3), rep("Thing 2", 3), rep("Thing 3", 3))
) -> xdf
ggplot(
  data = xdf, 
  aes(fill=parts, values=values)
) +
  geom_waffle(
    color = "white", 
    size = 1.125, 
    n_rows = 6
  ) +
  facet_wrap(~fct, ncol=1) +
  scale_x_discrete(
    expand = c(0,0,0,0)
  ) +
  scale_y_discrete(
    expand = c(0,0,0,0)
  ) +
  ggthemes::scale_fill_tableau(name=NULL) +
  coord_equal() +
  labs(
    title = "Faceted Waffle Geoms"
  ) +
  theme_ipsum_rc(grid="") +
  theme_enhance_waffle()

How would I adapt this code for my use?

First, I notice that the NYT version has partial squares on the bottom row of the charts. The area of those are difficult to interpret, so I’d forgo those and instead use full squares in my version of the waffle chart. This would result in the bottom row not having all 50 squares across.

Second, each waffle chart has its own title and in some cases, subtitle. I’d likely use {ggtext} to alter the facet titles to have a bolded title and regular font subtitle. I’d also like to make the subtitle font a smidge smaller than the facet title. If I can’t do this, then I might opt to use {patchwork} instead of facet_wrap() giving each plot its own title and subtitle and then the overall plot a title. I’d like to avoid {patchwork} because I can foresee a lot of duplicated code since each facet will require very similar code.

Third, each waffle chart also has text indicating the percent cut on the right side of the title. I’d likely do this with geom_text(). Since it would be positioned outside the plotting panel, I’d need to use coord_cartesian(clip = "off").

Finally, I’ve had a bit of a journey to find the data, but I think this PDF from the Congressional Budget Office (CBO) has the data we want in the 2026 column.

Workshops

I'm pleased to be able to offer you one of three recent workshops! With each you'll get access to 18 hours of video content, my code, and other materials. Click the buttons below to learn more

In case you missed it…

Here are some videos that I published this week that relate to previous content from these newsletters. Enjoy!

video preview

Finally, if you would like to support the Riffomonas project financially, please consider becoming a patron through Patreon! There are multiple tiers and fun gifts for each. By no means do I expect people to become patrons, but if you need to be asked, there you go :)

I’ll talk to you more next week!

Pat

Riffomonas Professional Development

Read more from Riffomonas Professional Development

Hey folks, I’m gearing up to teach a 1-day (6 hours) data visualization workshop on May 9th. This workshop will cover an introduction to the ggplot2 package and will assume no prior R knowledge. My goal is to help you to understand the ggplot2 framework and begin to apply it to make some interesting and compelling visualizations. From this workshop, I hope that you would be able to go off on your own journey learning more advanced topics. You can learn more and register by clicking the button...

Hey folks, I’m really excited to be offering a 1-day (6 hours) data visualization workshop on May 9th. It will cover the basics of ggplot2. If you’ve been following along this newsletter for anytime, you know I’ve thought a lot about how we learn. A critical element of learning is to create a mental model that we can hang ideas on to flesh out our understanding of a concept. The “grammar of graphics” is one such mental model for building plots. It is instantiated in ggplot2 - that’s the “gg”...

Hey folks, I somehow got through the month of March without a plot to commemorate the 5th anniversary of the COVID-19 pandemic. It is hard to believe that it has been five years. I know that my life and how I work has radically changed because of the pandemic. I started posting videos to YouTube and writing newsletters during the pandemic to help people who wanted to learn to use R while they were locked out of their labs. At one point I taught a workshop for U of Michigan researchers that...