[英]R ggplot geom_jitter duplicates outlier
Q1。 我正在使用ggplot的geom_boxplot繪制數據集。 但是,當我嘗試使用geom_jitter()繪制所有數據點時,我的數據中的異常值是重復的。 所有其他數據點都沒問題。 問題出在哪兒?
示例代碼:
PeakPeriod_24h <- c (31.05820, 23.83500, 24.36254, 25.31609, 24.21623, 23.90320)
condition <- rep("HL",6)
data_HL <- data.frame(condition, PeakPeriod_24h)
p <- ggplot(data_HL, aes(x=condition, y=PeakPeriod_24h, fill=condition))
p + geom_boxplot()+
geom_jitter(width = 0.3)+
theme_bw()+
coord_flip()+
geom_hline(aes(yintercept=24.18), colour="brown1", linetype="dotted", size = 1.4)+
scale_y_continuous(limits=c(), name = "Period Length")+
ggtitle("Boxplots\nHabitual Light")+
scale_fill_manual(values = c("gray60"))+
theme(plot.title = element_text(size=14, face="bold", vjust = .5),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.title.x = element_text(size=12, face = "bold"),
axis.text.x = element_text(size = 10, face = "bold", colour = "gray20"))+
guides(fill=FALSE)
謝謝!
嘗試
ggplot(data_HL, aes(x=condition, y=PeakPeriod_24h, fill=condition)) +
geom_boxplot(outlier.shape = NA) +
geom_jitter(width = 0.3)
異常值加倍,因為它是由geom_boxplot
繪制的(除非您指定不希望它為異常值繪制點),而另一次則由geom_jitter
。
對於第二個問題,你可以使用
geom_jitter(width = 0.3, aes(color=I(c("black", "blue")[code+1L])))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.