The following gives me a nice boxplot for each number of cylinders:
library(ggplot2)
data(mtcars)
ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot()
I have two outliers on the cyl=8 boxplot. How can I colour or shape these according to another factor, say factor(gear)
or factor(am)
?
To all those who marked this as duplicate please read both questions before assuming they are the same. The other question is about colouring the outliers the same colour as the box. My question is the opposite, I want to colour the outliers by the level of some other variable.