gpt4 book ai didi

R ggplot geom_jitter 重复异常值

转载 作者:行者123 更新时间:2023-12-04 09:41:04 40 4
gpt4 key购买 nike

一季度。我正在使用 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)

enter image description here

谢谢!

最佳答案

尝试

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]))) 

关于R ggplot geom_jitter 重复异常值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37498351/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com