9.10 Geometric objects cont.

  • Not every aesthetic works with every geom.

  • For example, you could set the shape of a point, but you couldn’t set the “shape” of a line. If you try, ggplot2 will silently ignore that aesthetic mapping.

  • On the other hand, you could set the linetype of a line. Here we see, geom_smooth() will draw a different line, with a different linetype, for each unique value of the variable that you map to linetype.

par(mar = c(4, 4, .1, .1))

# Left
ggplot(mpg, aes(x = displ, y = hwy, shape = drv))+
geom_smooth()
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
# Right
ggplot(mpg, aes(x = displ, y = hwy, linetype = drv))+ 
geom_smooth()
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'