September 2018
Beginner
206 pages
4h 27m
English
Boxplots are most appropriate when you want to check the distribution of a continuous y variable with some categorical (factor) x variable. We cannot create a boxplot of the mpg variable with the cyl variable in mtcars using the following code:
ggplot(mtcars, aes(cyl, mpg)) + geom_boxplot()
We will get a warning as follows:
Warning message: Continuous x aesthetic -- did you forget aes(group=...)?
The cyl variable is not explicitly declared as a factor variable in the mtcars dataset, so ggplot is confused about what the x variable is supposed to be. This is similar to when we created base plots with factor variables, though as we saw, plot() will still plot a variable not declared as a factor, but it will create a scatterplot instead ...
Read now
Unlock full access