Waffle charts - Learning from the NBA champs - A beginners example in R

19 games into the new NBA season, the Golden State Warriors have yet to loose a game. Sports casters are searching for words to express their surprise and fascination. The NBA regular season finally has the kind of story it did not have in years. The reigning champs play a brand of basketball that makes many of us believe we are witnessing a paradigm shift in pro basketball. Plus the Dubs got Steph Curry who might become the first MVP to earn an MIP award.

## Warning: package 'ggplot2' was built under R version 3.5.2

Since it’s hard to find the right words I thought the Warriors recent dominance might be a nice opportunity to say something using waffle charts. Some people describe waffle charts as rectangular pie charts. The waffle chart below shows how the Warriors pile up points: first and foremost they score a lot and they hit an unprecented amount of threes. Their 3-point shooting accounts for more than one third(!!) of their total points…

gsw + theme(legend.position="bottom") +
  ggtitle("How do the Warriors Score?")

Last year’s finals foe (no stranger to trey either), who continues to be among the NBAs elite teams cannot keep up by any means: fewer total points, fewer 3s, fewer 2s and fewer freebies. Plus, 3-point shots account for fewer that 30 percent of the Cavs points. Picture this: If the Warriors had not made a single free throw they would still have scored more points than the Cavs.

cle + theme(legend.position="bottom")

How to create this chart

Actually I had seen such charts before, but admittedly learned just recently that people call them waffle charts. However, I always thought they were a nice alternative to the boredom and limited information of regular pie charts. Plus, the come with an extra creative potential as the single squares can be replaced by icons – a technique we often encounter in well designed magazines. But, let me stay with the most basic example for now.

After I knew the name it is was easy to find out the obvious: there is an R package for that. Actually Bob Rudis’ waffle R package is available from CRAN and is thus easy to install. Also the package itself is very intuitive to use and beginneRs can create waffle charts within minutes even if they have never done it before. The waffle package is built on top of Hadley’s ggplot2, which means waffle charts can be customized using the mighty ggplot2 syntax and they profit from ggplot’s great documentation. And here’s the source code gist to reproduce my little example.

Matt Bannert
gut checks stack. makes public data public. runs on rap & open source.

I am interested in data science devOps for official statistics, open source, time series, rstats, Python and SQL. I contribute to RAdwords, tstools, timeseriesdb and kofdata.