Brian Wiley
Brian Wiley

Reputation: 505

Make Outliers same color as boxes in R

I have yet to find any solution on the net for list after a few hours. I want the outliers to be the same color as the boxes.

outlier.colour = NULL

Does not work. Here is code. This should be as easy as passing a par statement with the outcol and outbg parameters. I also saw a post to add the same argument for "scale_colour_manual with same colors but this doesn't work either.

library(datasets)
t <- ggplot(airquality, aes(factor(Month), Ozone))
t +  geom_boxplot(aes(fill=factor(Month)), outlier.size = 2, outlier.color = NULL) +
        scale_fill_manual(name = "Ozone Levels Per Month", values = c("pink", "green", "orange", "yellow", "blue"))

Upvotes: 0

Views: 281

Answers (1)

Roland
Roland

Reputation: 132706

The outliers inherit the color of the lines and not the fill color.

t +  geom_boxplot(aes(fill=factor(Month), color = factor(Month)), outlier.size = 2) +
  scale_fill_manual(name = "Ozone Levels Per Month", values = c("pink", "green", "orange", "yellow", "blue")) +
  scale_color_manual(name = "Ozone Levels Per Month", values = c("pink", "green", "orange", "yellow", "blue")) +
  geom_boxplot(aes(fill=factor(Month)), outlier.size = 2, outlier.colour = NA) #if you want grey lines

Upvotes: 1

Related Questions