我进行了方差分析测试,发现我的组中至少有一个平均值存在统计显着差异。作为后续分析,我进行了 Tukey 检验,发现哪些组的平均值不同,我希望在本文中介绍的箱线图中说明这一点,间歇性 Pringle 操作对肝硬化与正常肝脏的影响:
https://academic.oup.com/bjs/article/97/7/1062/6150536?login=true
我可以生成箱线图,但我想添加条形图来说明哪些组的平均值与星号显着不同,如图中突出显示的那样。有人知道我该如何解决这个问题,最好是在 SAS 或 R 中吗?
在 SAS 中,我使用 PROC SGPLOT 来生成箱线图,在 R 中,我知道我可以使用 geom_boxplot,但对于任何其他注释,我不确定可以使用哪些选项来完成此操作。
在 Base R 中,如果您想要更精细的控制,或者想要快速且看似自动化的方法,则可以手动生成这些行
ggstatsplot::ggbetweenstats
(我确信还有其他方法):
数据
set.seed(123)
df <- data.frame(DAST = 1:300,
Category = rep(c("Normal", "Chronic Hepatitis", "Liver Cirrhosis"), each = 100))
ggbetweenstats
方法请参阅 ?ggstatsplot::gg Betweenstats 了解如何自定义的选项
library(ggplot2)
library(ggstatsplot)
ggstatsplot::ggbetweenstats(df, x = Category, y = DAST)
彩色线条清晰可见
# vertical spacing between bars
v_spacing <- c(max(df$DAST) + seq(20, 50, length.out = 3))
plot(x = as.factor(df$Category), y = df$DAST,
xlab = NA, ylab = "D-AST", frame = FALSE)
# horizontal lines - position 1 = Chronic Hepatitis, 2 = Lover Cirrhosis, 3 = Normal
# bars map between positions 1-2, 1-3, 2-3
segments(x0 = c(1,1,2),
x1 = c(2,3,3),
y0 = v_spacing,
xpd = TRUE,
col = c("red", "green", "blue"))
# vertical lines
segments(x0 = c(1, 2, 1, 3, 2, 3),
y0 = rep(v_spacing, each = 2),
y1 = rep(v_spacing, each = 2) - 5,
xpd = TRUE,
col = rep(c("red", "green", "blue"), each = 2))
# Denote significance
text("*",
x = c(mean(1:2), mean(c(1,3)), mean(2:3)),
y = v_spacing + 5,
xpd = TRUE,
col = c("red", "green", "blue"))