DJHellduck February 2016

ggplot2 2.0.0 coloured boxplots and jitter with borders

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") 

Answers


thothal February 2016

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

Post Status

Asked in February 2016
Viewed 3,182 times
Voted 7
Answered 1 times

Search




Leave an answer