Heatmaps use case scenario

Intermediate Data Visualization with ggplot2

Rick Scavetta

Founder, Scavetta Academy

The barley dataset

head(barley, 9)
      yield   variety year            site
1  27.00000 Manchuria 1931 University Farm
2  48.86667 Manchuria 1931          Waseca
3  27.43334 Manchuria 1931          Morris
4  39.93333 Manchuria 1931       Crookston
5  32.96667 Manchuria 1931    Grand Rapids
6  28.96667 Manchuria 1931          Duluth
7  43.06666   Glabron 1931 University Farm
8  55.20000   Glabron 1931          Waseca
9  28.76667   Glabron 1931          Morris
Intermediate Data Visualization with ggplot2

A basic heat map

ggplot(barley, aes(year, variety, 
                   fill = yield)) + 
  geom_tile() +
  facet_wrap(vars(site), ncol = 1) +
  ...

Intermediate Data Visualization with ggplot2

A dot plot

ggplot(barley, aes(yield, variety, 
                   color = year)) + 
  geom_point(...) +
  facet_wrap(vars(site), ncol = 1) +
  ...

Intermediate Data Visualization with ggplot2

As a time series

ggplot(barley, aes(year, yield, 
                   group = variety,
                   color = variety)) + 
  geom_line() +
  facet_wrap(vars(site), nrow = 1) +
  ...

Intermediate Data Visualization with ggplot2

Using dodged error bars

ggplot(barley, aes(x = year, y = yield, 
                   group = site, 
                   color = site)) +
  stat_summary(fun = mean, 
               geom = "line", ...) +
  stat_summary(fun.data = mean_sdl, 
               geom = "errorbar", ...) +
  ...

Intermediate Data Visualization with ggplot2

Using ribbons for error

ggplot(barley, aes(x = year, y = yield, 
                   group = site, 
                   color = site)) +
  stat_summary(fun = mean, 
               geom = "line", ...) +
  stat_summary(fun.data = mean_sdl, 
               geom = "ribbon", ...) +
  ...

Intermediate Data Visualization with ggplot2

Coding Time!

Intermediate Data Visualization with ggplot2

Preparing Video For Download...