Coloring boxplot outlier points in ggplot2?

后端 未结 6 899
挽巷
挽巷 2020-12-05 11:18

How can I color the outlier points in ggplot2? I want them to be the same color as the boxplot itself. colour= is not enough to do this.

Example:

<
6条回答
  •  时光取名叫无心
    2020-12-05 11:46

    Update (2015-03-31): see @tarch's solution for ggplot2 >= 1.0.0

    solution for ggplot2 <= 0.9.3 is below.


    As @koshke said, having the outliers colored like the lines of the box (not the fill color) is now easily possible by setting outlier.colour = NULL:

    p <- ggplot(mtcars, aes(x=factor(cyl), y=mpg, col=factor(cyl)))
    p + geom_boxplot(outlier.colour = NULL)
    

    boxplot with coloured outliers

    • outlier.colour must be written with "ou"
    • outlier.colour must be outside aes ()

    I'm posting this as a late answer because I find myself looking this up again and again and I posted it also for the related question Boxplot, how to match outliers' color to fill aesthetics?

提交回复
热议问题