Tuning your bar and point charts

Visualization Best Practices in R

Nick Strayer

Instructor

A busy bar chart

who_disease %>% 
  filter(region == 'EMR', disease == 'measles', year == 2015) %>% 
  ggplot(aes(x = country, y = cases)) +
    geom_col()
Visualization Best Practices in R

Visualization Best Practices in R

Flipping the bar

  • geom_bar() and geom_col() don't allow categories on y-axis
    busy_bars <- who_disease %>% 
    filter(region == 'EMR', disease == 'measles', year == 2015) %>% 
    ggplot(aes(x = country, y = cases)) +
    geom_col() 
    
  • So we have to flip!
busy_bars + coord_flip() # swap x and y axes!
Visualization Best Practices in R

Visualization Best Practices in R

Excess grid

  • No need for parallel grid lines in bars
  • In point charts, only grids in line with point locations are needed

Visualization Best Practices in R

Visualization Best Practices in R

Removing vertical grid

plot <- who_disease %>% 
  filter(country == "India", year == 1980) %>% 
  ggplot(aes(x = disease, y = cases)) +
    geom_col()
# Remove vertical grid lines
 plot + theme(
    panel.grid.major.x = element_blank()
  )
Visualization Best Practices in R

Visualization Best Practices in R

Lighter background for point charts

  • Default gray background can be too low-contrast for points
  • theme_minimal() is a quick fix
  • Making points bigger helps too
who_subset %>% 
  ggplot(aes(y = reorder(country, cases_2016), x = log10(cases_2016))) +
  # Point size increased
  geom_point(size = 2) +
  # Theme minimal for light background
  theme_minimal()
Visualization Best Practices in R

Visualization Best Practices in R

Let's try it out!

Visualization Best Practices in R

Preparing Video For Download...