【问题标题】:R ggplot geom_jitter duplicates outlierR ggplot geom_jitter 重复异常值
【发布时间】:2016-05-28 11:21:22
【问题描述】:

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

谢谢!

【问题讨论】:

  • 我在运行您的代码时收到Error: object 'p' not found
  • 抱歉,忘记了代码中的一行。它现在在那里......

标签: r ggplot2


【解决方案1】:

试试

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

【讨论】:

  • 也感谢我。我希望我能算出我节省了多少时间,这要感谢像你这样的人在 Stack Overflow 上发布这样的内容,然后谷歌为我找到了它!
  • ... 翻倍 - 我也是如此。 :)
猜你喜欢
  • 1970-01-01
  • 2019-05-23
  • 1970-01-01
  • 1970-01-01
  • 2020-11-12
  • 1970-01-01
  • 1970-01-01
  • 2017-08-24
  • 1970-01-01
相关资源
最近更新 更多