使用 ggplot2 为箱线图中的极端异常值着色

问题描述 投票:0回答:1

我使用 ggplot2 创建了箱线图。我希望“极端”离群值(由

is_extreme
函数识别)的颜色与其他离群值不同。

这是我的代码:

ggplot(Mooney_data) + geom_boxplot(aes(x=Phase, y=RT), outlier.colour='red')+geom_point(data=Mooney_data[is_extreme(Mooney_data$RT),], aes(x= Phase, y=RT, col=factor(is_extreme(RT))))+ theme(legend.position='none')+mytheme

这给了我蓝色的极端异常值。但是,我不明白为什么其余的异常值是两种不同深浅的红色?我该如何纠正这个问题?

r ggplot2 boxplot outliers
1个回答
0
投票

您会得到两种不同的红色阴影,因为具有两个因素的 ggplot 的默认配色方案是

hue_pal()(2)
,第一个是您除了为异常值指定的“红色”之外看到的红色阴影.

library(scales)
hue_pal()(2)
[1] "#F8766D" "#00BFC4"

如果您想要蓝色极端异常值,请将

col
参数放在
geom_point
美学之外:

geom_point(data=Mooney_data[is_extreme(Mooney_data$RT),], 
aes(x= Phase, y=RT), 
col='blue'))  # <--- here
© www.soinside.com 2019 - 2024. All rights reserved.