使用 rstatix::wilcox_test()、rstatix::add_xy_position() 和 ggpubr::stat_pvalue_manual() 将 p 值位置错误地定义为零

The p value position is incorrectly defined as zero using rstatix::wilcox_test(), rstatix::add_xy_position(), and ggpubr::stat_pvalue_manual()

在对我的数据执行 rstatix::wilcox_test() 后,我自动添加了 y.position 值以使用 rstatix::add_xy_position() 绘制 p 值。然后我绘制数据并使用 ggpubr::stat_pvalue_manual() 添加 p 值。问题是 y.position 值被错误地定义为零,导致绘制的 p 值和括号 geom 出现在 y 轴的底部为零,而它应该出现在 y 轴的顶部附近。 rstatix 的文档指出 y.position 值,根据 max 默认设置计算,应该等于 max(data$Response) = 0.00008556344,而不是零。我是否错误地使用了这些功能?如果不是,如何让p值和括号geom出现在最大值对应的y轴数据值处?

library(tidyverse)
library(rstatix)
library(ggpubr)

# minimal data example
data <- tibble::tribble(
  ~Group,       ~Response,
  "Treatment",  3.210486e-06,
  "Control",    4.006825e-06,
  "Treatment",  4.350836e-06,
  "Control",    4.216934e-06,
  "Treatment",  4.415194e-06,
  "Control",    1.0260606e-05,
  "Treatment",  1.111064e-06,
  "Control",    1.0779088e-05,
  "Treatment",  3.57185e-07,
  "Control",    1.139097e-06,
  "Treatment",  0,
  "Control",    2.31074e-07,
  "Treatment",  5.78956e-07,
  "Control",    4.371157e-06,
  "Treatment",  6.5825e-08,
  "Control",    9.587202e-06,
  "Treatment",  2.65383e-07,
  "Control",    3.57337e-06,
  "Treatment",  7.14146e-07,
  "Control",    3.868605e-06,
  "Treatment",  1.2213951e-05,
  "Control",    6.936899e-06,
  "Treatment",  4.71707e-07,
  "Control",    5.5957173e-05,
  "Treatment",  1.265942e-06,
  "Control",    8.5563441e-05,
  "Treatment",  0,
  "Control",    0,
  "Treatment",  0,
  "Control",    2.1306289e-05,
  "Treatment",  5.2055e-07,
  "Control",    1.8420094e-05
)

# performing Wilcoxon test and adding 'y.position' for the p value
wilcoxon_result <- data %>%
  wilcox_test(Response ~ Group) %>%
  add_xy_position("Group")

# the 'y.position' is incorrectly defined as zero.
wilcoxon_result
#> # A tibble: 1 × 11
#>   .y.      group1  group2     n1    n2 statistic       p y.position groups  xmin
#>   <chr>    <chr>   <chr>   <int> <int>     <dbl>   <dbl>      <dbl> <name> <dbl>
#> 1 Response Control Treatm…    16    16      206. 0.00326          0 <chr>      1
#> # … with 1 more variable: xmax <dbl>

# the p value and bracket geom are plotted at zero.
ggplot(data, aes(Group, Response)) +
  stat_summary(geom = "errorbar", fun.data = mean_cl_boot, width = 0.25) +
  stat_summary(geom = "crossbar", fun = mean, fun.min = mean, fun.max = mean, fatten = FALSE, width = 0.5) +
  stat_pvalue_manual(wilcoxon_result, "P = {p}", size = 18 / ggplot2::.pt, tip.length = 0, bracket.size = 2 / ggplot2::.stroke) +
  theme_pubr(base_size = 18, x.text.angle = 45)

您的 y 位置似乎四舍五入为零,因为您正在处理非常小的数字。如果您将 Response 变量乘以 100 万,您将得到相同的结果 p-value,然后您可以除以 y 位置以使其位于您想要的任何位置:

# performing Wilcoxon test and adding 'y.position' for the p value
wilcoxon_result <- data %>%
  mutate(Response = Response * 1e6) %>%
  wilcox_test(Response ~ Group) %>%
  add_xy_position("Group") %>%
  mutate(y.position = y.position /3e6)

这给出:

wilcoxon_result
#> # A tibble: 1 x 11
#>  .y.      group1  group2       n1    n2 statistic       p y.position groups        xmin  xmax
#>  <chr>    <chr>   <chr>     <int> <int>     <dbl>   <dbl>      <dbl> <named list> <dbl> <dbl>
#>  Response Control Treatment    16    16      206. 0.00326  0.0000315 <chr [2]>        1     2

剧情是这样的:

ggplot(data, aes(Group, Response)) +
  stat_summary(geom = "errorbar", fun.data = mean_cl_boot, width = 0.25) +
  stat_summary(geom = "crossbar", fun = mean, fun.min = mean, 
               fun.max = mean, fatten = FALSE, width = 0.5) +
  stat_pvalue_manual(wilcoxon_result, "P = {p}", 
                     size = 18 / ggplot2::.pt, tip.length = 0, 
                     bracket.size = 2 / ggplot2::.stroke) +
  theme_pubr(base_size = 18, x.text.angle = 45)