0

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.

Epimetheus
  • 1,119
  • 1
  • 10
  • 19
  • You can adapt the answer of Dinre for previous question (part Coloring the outlier points) by changing color to shape and using different factor for that. – Didzis Elferts Oct 28 '13 at 17:48
  • Thanks @DidzisElferts but when I tried this it didn't work for me. Do you have an answer that solves the question? – Epimetheus Oct 28 '13 at 17:57
  • I'm guessing there is no way of doing this, short of the method for the other question. It seems like the sort of thing ggplot2 should offer without the user having to plot everything himself. Where's the best place to request a feature? – Epimetheus Oct 28 '13 at 18:12
  • 1
    Updated my answer to previous question to show one solution – Didzis Elferts Oct 28 '13 at 18:20
  • Great, that's very helpful @DidzisElferts but this isn't something I am going to want to do very often. It would be nice just to add color=mtcars$carb to the geom_boxplot call. That's the feature I would like to see in ggplot2. – Epimetheus Oct 28 '13 at 18:28

0 Answers0