The pie chart and its friends

Visualization Best Practices in R

Nick Strayer

Instructor

What is a proportion?

  • Parts making up a whole
  • Often used to understand population

Visualization Best Practices in R

The pie chart

  • Often the first technique people learn
  • Also, the first technique people learn to dislike
  • Dislike is not entirely warranted

Visualization Best Practices in R

A sour pie

  • Pie charts are not very precise
    • Data encoded in angles
  • Doesn't handle lots of classes well
    • After three slices it becomes hard to compare

Visualization Best Practices in R

A sweet pie

  • Intuitive and compact
who_disease %>% 
  mutate(
    region = ifelse(
      region %in% c('EUR', 'AFR'), 
      region, 'Other')
  ) %>% 
  ggplot(aes(x = 1, fill = region)) +
    geom_bar(color = 'white') +
    coord_polar(theta = "y") +
    theme_void()

Visualization Best Practices in R

The waffle chart

  • More precise than pie charts
  • Encode data in area, not angles
obs_by_region <- who_disease %>%
  group_by(region) %>% summarise(num_obs = n()) %>% 
  mutate(percent = round(num_obs/sum(num_obs)*100))

# Array of rounded percentages
percent_by_region <- obs_by_region$percent
names(percent_by_region) <- obs_by_region$region

# Send array of percentages to waffle plot function
waffle::waffle(percent_by_region, rows = 5)
Visualization Best Practices in R

The waffle chart

Visualization Best Practices in R

Let's practice!

Visualization Best Practices in R

Preparing Video For Download...