[英]How to change color of outliers when using geom_boxplot
I have made several different attempts to change the fill color of the outliers for a boxplot I'm constructing, to no avail.我进行了几次不同的尝试来更改我正在构建的箱线图的异常值的填充颜色,但无济于事。 Any help is appreciated.
任何帮助表示赞赏。 This is my code so far...
到目前为止,这是我的代码...
# Load the dataset.
data <- read.csv("C:\\School\\Statistics\\bearWeight.csv")
# Initialize dataframe variable for both WEIGHT & Relative Frequency
WEIGHT <- data$WEIGHT
RelativeFrequency <- data$Relative.Frequency
# Load ggplot2
library(ggplot2)
bearWeightBoxPlot <- ggplot(data, aes(x=WEIGHT, y=RelativeFrequency, group = 1))
bearWeightBoxPlot <- bearWeightBoxPlot +
geom_boxplot(colour = "#3366FF", outlier.colour = "black",
outlier.shape = 24, outlier.fill = "red", outlier.size = 3)
bearWeightBoxPlot <- bearWeightBoxPlot +
geom_jitter(width = 0.2) +
coord_flip()
plot(bearWeightBoxPlot)
We need the argument outlier.fill
and shapes from 21 to 25.我们需要参数
outlier.fill
和从 21 到 25 的形状。
library(ggplot2)
p <- ggplot(mpg, aes(class, hwy))
p + geom_boxplot(outlier.colour = "black",
outlier.shape = 24,
outlier.fill = "red",
outlier.size = 3 # not actually needed
)
An overview about possible shapes can be found here: www.cookbook-r.com可以在此处找到有关可能形状的概述: www.cookbook-r.com
Change the shape of outliers to be colored by fill aesthetic (shape = 21 to fill the shape with chosen fill)将异常值的形状更改为填充美学(形状 = 21 以使用所选填充填充形状)
ggplot(iris,aes(Species,Sepal.Width,fill="skyblue1"))+ geom_boxplot(outlier.shape = 21) ggplot(iris,aes(Species,Sepal.Width,fill="skyblue1"))+ geom_boxplot(outlier.shape = 21)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.