我正在为一次会议绘制一个图,并想添加更多的意义栏。这是我的代码:
bxp_stress <-
subjstress %>%
ggboxplot( x = "timetask",
y = "Stress",
fill = "group",
xlab = "timepoint",
ylab = "subjective rating [VAS]",
title = "Subjective stress"
)+
scale_fill_manual(values = my_palette) +
scale_x_discrete(labels = c("pre-ctrl", "post-ctrl", "pre-stress", "post-stress")) +
geom_signif(comparisons = list(c("MAST_pre", "MAST_post"), c("plac_post", "MAST_post")),
annotations = "***",
step_increase = 0.05,
map_signif_level = TRUE,
vjust = 0.4,
tip_length = 0)
我的情节看起来如何:
现在我想为“三组之间的后应力”添加显着性条(在 ggboxplot 的“fill”参数中定义)。 我该如何做到这一点,因为仅在 2 个组(NC 与 IUD)之间发现显着性,并且我不想要整体显着性,因为我正在使用以下代码:
bxp_stress + stat_compare_means(aes(group = group), label = "p.signif")
编辑:这就是我的想象:
编辑2:可用的数据框
subjstress <- tibble(
group = rep(c("NC", "IUD", "OC"), each = 232),
timetask = rep(c("plac_pre", "plac_post", "MAST_pre", "MAST_post"), times = 174),
Stress = sample(0:100, 696, replace = TRUE)
)
您可以首先使用
add_significance
和 t 检验创建数据框来绘制显着性。之后,您可以通过使用 filter
修改绘制的图层,仅绘制所需的组,如下所示:ggplot_build
library(ggpubr)
library(dplyr)
library(rstatix)
stat.test <- subjstress %>%
group_by(timetask) %>%
t_test(Stress ~ group) %>%
adjust_pvalue() %>%
add_significance("p.adj") %>%
add_xy_position(x = "timetask")
stat.test
#> # A tibble: 12 × 16
#> timetask .y. group1 group2 n1 n2 statistic df p p.adj
#> <chr> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 MAST_post Stress IUD NC 58 58 0.998 113. 0.32 1
#> 2 MAST_post Stress IUD OC 58 58 0.840 113. 0.402 1
#> 3 MAST_post Stress NC OC 58 58 -0.159 114. 0.874 1
#> 4 MAST_pre Stress IUD NC 58 58 0.851 114. 0.396 1
#> 5 MAST_pre Stress IUD OC 58 58 1.51 113. 0.134 1
#> 6 MAST_pre Stress NC OC 58 58 0.649 114. 0.518 1
#> 7 plac_post Stress IUD NC 58 58 -0.142 113. 0.888 1
#> 8 plac_post Stress IUD OC 58 58 -0.581 114. 0.562 1
#> 9 plac_post Stress NC OC 58 58 -0.415 114. 0.679 1
#> 10 plac_pre Stress IUD NC 58 58 -1.09 114. 0.279 1
#> 11 plac_pre Stress IUD OC 58 58 0.0732 114. 0.942 1
#> 12 plac_pre Stress NC OC 58 58 1.17 114. 0.246 1
#> # ℹ 6 more variables: p.adj.signif <chr>, y.position <dbl>,
#> # groups <named list>, x <dbl>, xmin <dbl>, xmax <dbl>
p <- subjstress %>%
ggboxplot( x = "timetask",
y = "Stress",
fill = "group",
xlab = "timepoint",
ylab = "subjective rating [VAS]",
title = "Subjective stress"
) +
stat_pvalue_manual(
stat.test, label = "p.adj.signif", tip.length = 0.01
) +
scale_x_discrete(labels = c("pre-ctrl", "post-ctrl", "pre-stress", "post-stress"))
p