用Boxplots填充离群值相同的颜色在ggplot R中填充颜色?

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

我希望离群值显示为与箱线图填充颜色相同的颜色(而不是轮廓线)。我尝试了不同的方法,但没有一个起作用。任何帮助将不胜感激。

ToothGrowth$dose <- as.factor(ToothGrowth$dose)
p <- ggplot(ToothGrowth, aes(x=dose, y=len))+
     geom_boxplot(width=0.3,aes(fill=dose),outlier.colour = NA)+
     geom_point()+
     scale_fill_manual(values=c("firebrick", "royalblue","yellow"))
p

boxplots for different doses

r boxplot fill outliers
2个回答
0
投票

我不确定您要寻找什么。也许这可以回答您的问题:

ToothGrowth$dose <- as.factor(ToothGrowth$dose)
ggplot(ToothGrowth, aes(x=dose, y=len))+
  geom_boxplot(width=0.3,aes(fill=dose), outlier.colour = NA)+
  geom_point(aes(color=dose))+
  scale_fill_manual(values=c("firebrick", "royalblue","yellow"))+
  scale_color_manual(values=c("firebrick", "royalblue","yellow"))

为您提供


0
投票

我们可以将outlier.shape设置为“ 21”,以便它将继承填充颜色并在箱线图之前绘制点:

ggplot(mtcars, aes(x=factor(cyl), y=mpg, fill = factor(cyl))) + 
  geom_point() +
  geom_boxplot(outlier.shape = 21) +
  scale_fill_manual(values=c("firebrick", "royalblue","yellow"))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.