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

使用ggpubr包的ggbarplot时含NA组的误差条偏移问题

ggpubr绘图时含NA组导致误差条偏移的问题

当数据集中所有组均有观测值时,代码可正常运行。但当某一组数据为NA时,误差条会出现偏移现象。

无NA值的正常示例

library(ggpubr)
# 加载ToothGrowth数据集
data(ToothGrowth)
ggbarplot(ToothGrowth, x = "dose", y = "len", 
   add = "mean_se", 
   color = "supp", palette = "jco",
   position = position_dodge(0.8)
) + 
  ggtitle("数据集中无NA值")

绘图结果:各组误差条与对应条形图精准对齐,整体布局规整。

含NA值的异常示例

# 修改数据集
ToothGrowth$len[ToothGrowth$dose == 2 & ToothGrowth$supp == "VC"] <- NA

head(ToothGrowth)
ggbarplot(ToothGrowth, x = "dose", y = "len", 
   add = "mean_se", 
   color = "supp", palette = "jco",
   position = position_dodge(0.8)
)+
  ggtitle存在NA值的组"

绘图结果:dose=2的VC组因数据全为NA,对应的误差条出现偏移,无法与条形图正确对齐。

内容的提问来源于stack exchange,提问作者Yujie Liu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 23:07:35