[英]How to group Boxplots without use of color or fill in ggplot2
[英]Fill outliers with same color as Boxplots Fill color in ggplot R?
我們可以將outlier.shape
設置為“21”,這樣它將繼承填充 colors 和 plot 箱線圖之前的點:
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
ggplot(ToothGrowth, aes(x=dose, y=len))+
geom_point()+
geom_boxplot(width=0.3,aes(fill=dose),outlier.shape = 21)+
scale_fill_manual(values=c("firebrick", "royalblue","yellow"))
編輯還要在框內顯示點:
is_outlier <- function(x) {
return(x < quantile(x, 0.25) - 1.5 * IQR(x) | x > quantile(x, 0.75) + 1.5 * IQR(x))
}
ToothGrowth %>%
group_by(dose) %>%
mutate(outlier = ifelse(is_outlier(len), as.numeric(NA), as.numeric(len))) %>%
ggplot(aes(x=dose, y=len))+
geom_boxplot(width=0.3,aes(fill=dose),outlier.shape = 21)+
geom_point(aes(x = dose, y = outlier))+
scale_fill_manual(values=c("firebrick", "royalblue","yellow"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.