2 min read

Cloudy with a chance of pie

Matt Dray

The pinnacle of visualisation

Great news everyone: I’ve taken the best of two stellar data visualisations and smashed them together into something that can only be described as perfection.

Michael Fassbander as Steve JObs saying 'perfection'

Let me set the scene. There’s three things we can agree on:

  1. Everyone loves pie charts, particularly when they’re in 3D, exploded and tilted.
  2. Word clouds aren’t at all overused.
  3. I have too much time on my hands.

With that in mind, I’ve artfully melded clouds and pies into the function cloud_pie, which I think sounds rather sweet.

You can find the function in my personal package dray, which I made following Hilary Parker’s excellent ‘Writing an R Package from Scratch’ blogpost.


Pie in the sky

cloud_pie depends on the plotrix and wordcloud packages and takes three arguments:

  • data: summary dataframe with two columns: categories, and counts for those categories
  • name_col: column containing the category names
  • count_col: column containing the counts for each category

data must be a dataframe with a column of categories (i.e. name_col) and a column of count values associated with those categories (i.e. count_col).

It’s also completely untested and will probably break if you actually try to use it. So let’s try to use it.

Pokemon data, of course

Let’s use the same data as in the Pokeballs in Super Smash Bros blog post, which is hosted on GitHub.

library(dplyr)  # pipes and data manipulation

#read raw data
pkmn_raw <- read.csv("https://raw.githubusercontent.com/matt-dray/draytasets/master/ssb_pokeballs.csv")

# shape the data
pkmn_summary <- pkmn_raw %>%
  group_by(pokemon) %>%
  count() %>%

# take a look
## Observations: 13
## Variables: 2
## $ pokemon <fct> beedrill, blastoise, chansey, charizard, clefairy, gol...
## $ n       <int> 26, 25, 26, 23, 18, 26, 25, 24, 20, 3, 25, 26, 23

Hold on tight

Accept your fate.

  data = pkmn_summary,
  name_col = "pokemon",
  count_col = "n"

Did I forget to mention that the typeface is gothic and colours are selected randomly from the named colours that R knows about? The words and pie slices are sized by frequency and match up by colour. Sensational.

You know what to do

Let me know if you decide to nominate me for an Information is Beautiful award.