首页 > 解决方案 > ggplot2 显着性水平,带星号,调整后的 p 值

问题描述

我是 R 的初学者,我想知道是否可以使用 ggplot2 包在数据可视化方面获得一些帮助。

我试图用调整后的 p 值(使用 Bonferroni 校正)而不是带星号的正常 p 值来标记显着性水平。

我试过的代码是......

stat_compare_means(aes(label=..p.adj.., group=sample_type), label = "p.signif", method = "t.test", hide.ns = TRUE)

stat_compare_means(aes(group=sample_type), p.adjust.method = "bonferroni", label = "p.signif", method = "t.test", hide.ns = TRUE)

标签: rggplot2statisticsp-value

解决方案


请参阅此EnvStats包。作者提供的示例(第 1180 页)是:

library(ggplot2)
library(EnvStats)
p <- ggplot(mtcars, aes(x = factor(cyl), y = mpg, color =     
factor(cyl))) + theme(legend.position = "none")

dev.new()
p + geom_point() +
stat_n_text() + stat_mean_sd_text() +
stat_test_text() +
labs(x = "Number of Cylinders", y = "Miles per Gallon")

推荐阅读