Cloudy with a chance of pie

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 Fassbender 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.

remotes::install_github("matt-dray/dray")
library(dray)

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.

Pokémon data, of course

Let’s use the same data as in the Pokéballs 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() %>%
  ungroup()

# take a look
glimpse(pkmn_summary)
## Observations: 13
## Variables: 2
## $ pokemon <fct> beedrill, blastoise, chansey, charizard, clefairy, goldeen, h…
## $ n       <int> 26, 25, 26, 23, 18, 26, 25, 24, 20, 3, 25, 26, 23

Hold on tight

Accept your fate.

dray::cloud_pie(
  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.


Session info

## ─ Session info ───────────────────────────────────────────────────────────────
##  setting  value                       
##  version  R version 3.6.0 (2019-04-26)
##  os       macOS Mojave 10.14.6        
##  system   x86_64, darwin15.6.0        
##  ui       X11                         
##  language (EN)                        
##  collate  en_GB.UTF-8                 
##  ctype    en_GB.UTF-8                 
##  tz       Europe/London               
##  date     2020-05-17                  
## 
## ─ Packages ───────────────────────────────────────────────────────────────────
##  package      * version    date       lib source                         
##  assertthat     0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                 
##  blogdown       0.12       2019-05-01 [1] CRAN (R 3.6.0)                 
##  bookdown       0.10       2019-05-10 [1] CRAN (R 3.6.0)                 
##  cli            2.0.1      2020-01-08 [1] CRAN (R 3.6.0)                 
##  crayon         1.3.4      2017-09-16 [1] CRAN (R 3.6.0)                 
##  curl           4.3        2019-12-02 [1] CRAN (R 3.6.0)                 
##  digest         0.6.23     2019-11-23 [1] CRAN (R 3.6.0)                 
##  dplyr        * 0.8.3      2019-07-04 [1] CRAN (R 3.6.0)                 
##  dray         * 0.0.0.9000 2020-02-09 [1] Github (matt-dray/dray@64017be)
##  evaluate       0.14       2019-05-28 [1] CRAN (R 3.6.0)                 
##  fansi          0.4.1      2020-01-08 [1] CRAN (R 3.6.0)                 
##  gifski         0.8.6      2018-09-28 [1] CRAN (R 3.6.0)                 
##  glue           1.3.1      2019-03-12 [1] CRAN (R 3.6.0)                 
##  htmltools      0.4.0      2019-10-04 [1] CRAN (R 3.6.0)                 
##  knitr          1.26       2019-11-12 [1] CRAN (R 3.6.0)                 
##  magrittr       1.5        2014-11-22 [1] CRAN (R 3.6.0)                 
##  pillar         1.4.3      2019-12-20 [1] CRAN (R 3.6.0)                 
##  pkgconfig      2.0.3      2019-09-22 [1] CRAN (R 3.6.0)                 
##  plotrix        3.7-7      2019-12-05 [1] CRAN (R 3.6.0)                 
##  purrr          0.3.3      2019-10-18 [1] CRAN (R 3.6.0)                 
##  R6             2.4.1      2019-11-12 [1] CRAN (R 3.6.0)                 
##  RColorBrewer   1.1-2      2014-12-07 [1] CRAN (R 3.6.0)                 
##  Rcpp           1.0.3      2019-11-08 [1] CRAN (R 3.6.0)                 
##  remotes        2.1.0      2019-06-24 [1] CRAN (R 3.6.0)                 
##  rlang          0.4.4      2020-01-28 [1] CRAN (R 3.6.0)                 
##  rmarkdown      2.0        2019-12-12 [1] CRAN (R 3.6.0)                 
##  sessioninfo    1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                 
##  stringi        1.4.5      2020-01-11 [1] CRAN (R 3.6.0)                 
##  stringr        1.4.0      2019-02-10 [1] CRAN (R 3.6.0)                 
##  tibble         2.1.3      2019-06-06 [1] CRAN (R 3.6.0)                 
##  tidyselect     0.2.5      2018-10-11 [1] CRAN (R 3.6.0)                 
##  utf8           1.1.4      2018-05-24 [1] CRAN (R 3.6.0)                 
##  vctrs          0.2.2      2020-01-24 [1] CRAN (R 3.6.0)                 
##  withr          2.1.2      2018-03-15 [1] CRAN (R 3.6.0)                 
##  wordcloud      2.6        2018-08-24 [1] CRAN (R 3.6.0)                 
##  xfun           0.11       2019-11-12 [1] CRAN (R 3.6.0)                 
##  yaml           2.2.1      2020-02-01 [1] CRAN (R 3.6.0)                 
## 
## [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library