首页 > 解决方案 > 如何在R ggboxplot中按组生成上下误差线?

问题描述

我正在尝试使用 R 创建带有“星”符号的分组箱线图ggboxplot。但是,我在添加误差线时遇到了困难,尤其是上下水平线。这是我的代码和输出。

library(ggpubr)
library("ggsignif")
s=15
p <- ggboxplot(data, x = "MRI", y = "featurevalue",
               color = "black",fill="filename",palette = "aaas",
               notch = TRUE,outline=FALSE,
               font.x = s,font.y = s,
               font.xtickslab = s,font.ytickslab = s,
               font.legend = s,
               legend.title="",
               ylim = c(0, 1.04))
p + 
  stat_compare_means(size=8,aes(group = filename),label = "p.signif",hide.ns = TRUE,method = "t.test") + 
  theme(panel.border=element_rect(fill='transparent',color='black')) + 
  theme(legend.background=element_rect(fill="transparent",colour="black"), 
  legend.position=c(0.85,0.93),
  legend.title = element_blank(),
  legend.margin=margin(c(0.1,0.1,0.1,0.1), unit='cm'),
  legend.key = element_blank(),
  plot.margin=unit(c(0.2,0.2,0.1,0.1),'lines'))

有人说使用ggplot2会自动出现错误栏。但我不能用ggplot2. 我曾尝试使用error.plot = c("upper_errorbar", "lower_errorbar")inggboxplot来添加错误栏,但此命令似乎不适用于分组箱线图,我在下面显示了我得到的图。有没有正确的方法来组合这个推荐和add.params = list(group=),以生成分组误差条?

在此处输入图像描述

任何人都可以帮助在分组箱线图中生成误差线吗?谢谢你的帮助!

标签: rrstudioboxplot

解决方案


您是否尝试过 ggboxplot() 函数中的“错误栏”参数?

bxp.errorbar = TRUE

在 ggboxplot() 函数中给出上述参数并检查。


推荐阅读