只有四个数据,但图上出现五个点?

2022-08-21  本文已影响0人  小汪Waud

数据为真实数据修改后的数据。

很早之前给师姐调试了一个适配她大批量实验的作图代码,最近她发现有些问题,部分组数据只有四个,但图中却出现了五个点!

使用代码如下

rm(list = ls())
data = read.csv(file = "test.txt",header = T,sep = "\t")
library(tidyr)
ldata = pivot_longer(data = data,
                     cols = starts_with("X"),
                     names_to = "sample",
                     values_to = "length")

library(ggplot2)
library(ggsci)
library(ggpubr)

ldata$Shoot_length <- factor(ldata$Shoot_length,
                             levels=c(unique(ldata$Shoot_length)),ordered = TRUE) 

data$Shoot_length 


ggplot(data = ldata ,aes(x = Shoot_length, y = length))+ 
  stat_boxplot(geom = "errorbar",
               width=0.1)+
  geom_boxplot(widths = 0.1)+
  geom_jitter()+
  theme_classic()+
  scale_color_aaas() +
  theme(plot.subtitle = element_text(size = 15,hjust = 0.5), 
        legend.title = element_text(size = 12))+
  labs(x = NULL, y = NULL,color = "Group")+ 
  theme(axis.text.x = element_text(size = 15),axis.text.y = element_text(size = 15))+ 
 theme(legend.text = element_text(size = 12),legend.title = element_text(size = 14))

这要是解决不了,妥妥的学术造假啊!

经过检索,我们找到了答案。其实问题非常简单,geom_boxplot() 函数里有一批专门针对离群值 (outlier) 进行标注的参数。

如果我们使用geom_point(),实际上outlier只是对离群点进行了标注。默认情况下,标注会和原点属性相同(重合),因此只能看到一个点。

而一旦我们使用了geom_jitter(),那么因其“抖动”的属性,标注和原点就会分离开来,这也就造成了两个点的假象。

上一篇 下一篇

猜你喜欢

热点阅读