R语言 是否有办法更改星号以匹配自定义p值?

toiithl6  于 2023-07-31  发布在  其他
关注(0)|答案(1)|浏览(182)

对于我的论文,我需要将pvalues格式设置为pvalue< 0.1,已经显示为有效值(*)。其他值应保持不变(因此**< 0.01等)。
我之前使用了ggplot的这一部分:

stat_compare_means(aes(label = paste0('', after_stat(p.format), ' ',
after_stat(p.signif))), label.y = 450,
vjust = 1, method = "t.test", ref.group = "0", size=3,fontface="bold")

字符串
它结合了p值和星号。当然,它显示了“正常”p值的星号(即。*< 0.05,ns > 0.05)。

lymnna71

lymnna711#

如果你看一下?stat_compare_means,你会发现参数symnum.args的描述:

symnum.args

传递给函数symnum的参数列表,用于p值的符号数字编码。例如,symnum.args = list(cutpoints = c(0, 0.0001, 0.001, 0.01, 0.05, 1), symbols = c("****", "***", "**", "*", "ns")).
如果没有一个可重复的例子,很难看出这里的答案如何能增加很多,但我想我们可以生成一个近似于你的假数据集:

library(ggpubr)

set.seed(4)

df <- data.frame(xvals = rep(0:4, each = 100), 
                 yvals = rnorm(500, rep(71:75 * 5, each = 100), 25))

ggboxplot(df, x = "xvals", y = "yvals",
          color = "xvals", palette = "npg") +
  stat_compare_means(aes(label = paste0('', after_stat(p.format), ' ',
                                        after_stat(p.signif))), 
        label.y = 450, vjust = 1, method = "t.test",
        ref.group = "0", size = 3, fontface = "bold",
        symnum.args = list(cutpoints = c(0, 0.0001, 0.001, 0.01,  0.1, 1), 
                           symbols = c("****", "***", "**", "*", "ns")))

字符串
x1c 0d1x的数据
创建于2023-07-24带有reprex v2.0.2

相关问题