使用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
相关产品推荐
相关产品推荐

