1

I am trying to make a boxplot filled by a binary variable, with a facet grid. I also want to have jitter on top of the boxplots, but without getting them confused with the outliers. In order to fix this, I have added colour to the jitter, but by doing so, they meld in with the already coloured boxplots, as they are the same colour.

I really want to keep the colours the same, so is there a way to add borders to the jitter (or is there a different way to fix the outlier problem)?

Example code:

plot <- ggplot(mpg, aes(class, hwy))+
   geom_boxplot(aes(fill = drv))+
   geom_jitter(width = .3, aes(colour =drv))
 #  facet_grid(. ~some_binary_variable, scales="free") 
FredrikH-R
  • 142
  • 11

1 Answers1

3

You can use a filled plotting symbol (21:25, cf. ?pch) and then use a white border to differentiate the points:

ggplot(mpg, aes(class, hwy))+
    geom_boxplot(aes(fill = drv))+
    geom_jitter(width = .3, aes(fill = drv), shape = 21, color = "white")

enter image description here

FredrikH-R
  • 142
  • 11
thothal
  • 16,690
  • 3
  • 36
  • 71
  • It works, thank you! I see now that I messed up when plotting the variables, so I edited that in my question. Will try to edit yours too if i can, so the graph looks prettier. – FredrikH-R Feb 08 '16 at 12:51