本文介绍了Boxplot,如何匹配离群值的颜色来填充美学?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图将boxplot的异常值颜色与由美学(scale_colour_discrete)设置的填充颜色匹配。 下面是一个示例。 m fill = factor动画)))m + geom_boxplot()+ scale_y_log10() 我如何将这些黑点改成身体所用的红/绿颜色?如果我理解正确,boxplot的outlier.colour选项似乎选择一种颜色,而不是审美。如果有帮助,我不介意使用颜色美学。 编辑: 改编此。 I am trying to match boxplot's outliers color to the fill color which is set by aesthetic (scale_colour_discrete).Here is an example.m <- ggplot(movies, aes(y = votes, x = factor(round(rating)), fill=factor(Animation)))m + geom_boxplot() + scale_y_log10()This generates plot below. How do I change those black dots to be reddish/greenish colors used in the body? outlier.colour option of the boxplot seems to pick one colour across, and not as aesthetic, if I understand correctly. I dont mind using colour aesthetics if that helps. Edit:Adapted this solution (Changing whisker definition in geom_boxplot). The horizontal dodging is reset by stats_summary and I couldn't figure out how to get it back. I'd ptobably drop outliers and stretch whiskers as needed since I know how now.# define the summary functionf <- function(x) { r <- quantile(x, probs = c(0.05, 0.25, 0.5, 0.75, 0.95)) names(r) <- c("ymin", "lower", "middle", "upper", "ymax") r}# define outlier function, beyound 5 and 95% percentileso <- function(x) { subset(x, x < quantile(x,probs=c(0.05))[1] | quantile(x,probs=c(0.95))[1] < x)}m <- ggplot(movies, aes(y = votes, x = factor(round(rating)), colour=factor(Animation)))m <- m + stat_summary(fun.data=f, geom='boxplot')m <- m + stat_summary(fun.y=o, geom='point', aes(colour=factor(Animation)))m + scale_y_log10() 解决方案 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:m <- ggplot(movies, aes(y = votes, x = factor(round(rating)), colour = factor(Animation)))m + geom_boxplot(outlier.colour = NULL) + scale_y_log10()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 also posted it for the related question Coloring boxplot outlier points in ggplot2?. 这篇关于Boxplot,如何匹配离群值的颜色来填充美学?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-24 15:50