B.7 Faceting with facet_wrap

For categorical variables, we can create a separate window for each value of that variable. Here we make separate scatter plots for each season.type, reg and post. Note that if we use geom_smooth, there’s a line for each window and color.

Code
g = ggplot(d, aes(x = ascore, 
                  y = hscore, 
                  color = season.type))+
  geom_point()+
  geom_smooth(method = 'lm')+
  facet_wrap(~season.type)
g %>% 
  pub(xlim = c(65, 165), 
      ylim = c(65, 165))

[1] 57.35768
[1] 80
[1] 20
[1] 157.3577