9.4 Mapping categorical variables to aesthetics cont.

  • Similarly, we can map class to size or alpha (transparency) aesthetics as well.

  • We get warnings because mapping a non-ordinal discrete variable (class) to an ordered aesthetic (size or alpha) is generally not a good idea because it implies a ranking that does not in fact exist.

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

# Left
ggplot(mpg, aes(x = displ, y = hwy, size = class))+
geom_point()
## Warning: Using size for a discrete variable is not advised.
# Right
ggplot(mpg, aes(x = displ, y = hwy, alpha = class))+
geom_point()
## Warning: Using alpha for a discrete variable is not advised.