17 ggplot2

17.1 Slides

Workshop: Introduction to ggplot2

Date: November 2 2017

Slides and Resources

17.3 Facets

Facet wrap using categorical columns:

ggplot(diamonds, aes(depth, price)) + 
  geom_point() + 
  facet_wrap(~cut)

Facet wrap using automatically binned values:

“What if I look at four separate chunks of the data, with approximately the same number of points”

ggplot(diamonds, aes(depth, price)) + 
  geom_point() + 
  facet_wrap(~ cut_number(carat, 4))

“What if I look at four separate chunks of the data, with the equal ranges in each group?”

ggplot(diamonds, aes(depth, price)) + 
  geom_point() + 
  facet_wrap(~ cut_interval(carat, 4))

“What if I look at four separate chunks of the data, with a specific width of values in each group?”

ggplot(diamonds, aes(depth, price)) + 
  geom_point() + 
  facet_wrap(~ cut_width(carat, 0.5))

17.4 Combining plots

The one and only: patchwork.