You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R中ggboxplot结合geom_point绘图时y轴最大值处出现额外点的问题

箱线图绘制时出现额外数据点的问题

使用R的ggboxplot绘制箱线图,通过geom_point添加单个数据点,并借助position = position_jitter(width = 0.2)分散点后,生成的图表始终在y轴最大值位置额外多出一个点(如样本量n=12时,会显示13个点),目前无法定位问题原因。

绘图代码

plot <- ggboxplot(data, x = "treatment", y = "value", fill = "treatment", width = 0.4) + 
  stat_summary(fun="mean", geom="point", shape=23, size=3, fill="white", position = position_dodge(width = 0.7)) +
  geom_point(data = data, aes(x = treatment, y = value),
             position = position_jitter(width = 0.2)) +
  labs(x = "Treatment", y = "Concentration") +
  guides(fill = "none") +
  scale_fill_manual(values = cb_palette) +
  scale_y_continuous(breaks = c(5,10,15,20,25,30,35), limits = c(5,32)) +
  theme_bw(base_size = 18) +
  theme(panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.minor.y = element_blank()
        )

plot

示例数据集

sample  treatment   value
1   1   12.15980346
1   2   10.97915135
1   3   10.24602834
1   4   12.00826926
2   1   10.53893152
2   2   9.62200229
2   3   8.661327288
2   4   9.47010368
3   1   7.980431308
3   2   8.299834385
3   3   6.167766975
3   4   8.725891659
4   1   10.95137118
4   2   12.79031335
4   3   10.4178423
4   4   11.20135523
5   1   11.60301628
5   2   13.78625968
5   3   13.61339271
5   4   12.8500865
6   1   8.806134878
6   2   9.18175894
6   3   9.95901536
6   4   8.878521261
7   1   11.56143798
7   2   11.14678642
7   3   15.99024738
7   4   14.47572695
8   1   16.72820906
8   2   15.91346874
8   3   16.18871308
8   4   14.47575009
9   1   16.23862546
9   2   14.78037788
9   3   15.10731239
9   4   14.96026006
10  1   9.84265316
10  2   12.25204501
10  3   9.44290475
10  4   11.78481592
11  1   17.9120574
11  2   15.3130744
11  3   16.49442194
11  4   18.19518935
12  1   24.84358568
12  2   26.38818249
12  3   30.31382726
12  4   21.29795724

已尝试的解决方法

  • 重写绘图代码
  • 将数据保存为xlsx、csv等不同格式后重新读取
  • 改用ggplot编写绘图代码

恳请提供解决思路或方案!

内容的提问来源于stack exchange,提问作者Andrew Tilley

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 18:40:17