【发布时间】:2018-01-10 15:07:33
【问题描述】:
我正在尝试使用 ggplot2 和 ggpubr 包以星号的形式向我的 boxplots 添加显着性级别,但我有很多比较,我只想显示重要的。
我尝试使用 stat_compare_means 中的选项 hide.ns=TRUE,但它显然 不起作用,这可能是 ggpubr 包中的错误。
此外,您看到我在成对 wilcox.test 比较中省略了组“PGMC4”; kruskal.test 我怎样才能把这个组排除在外?
我的最后一个问题是显着性水平是如何工作的?如 * 低于 0.05,** 低于 0.025,*** 低于 0.01? ggpubr 使用的约定是什么?它是显示 p 值还是调整后的 p 值?如果是后者,调整方法是什么? BH?
请在下方查看我的 MWE 和 this link 和 this other one 以供参考
##############################
##MWE
set.seed(5)
#test df
mydf <- data.frame(ID=paste(sample(LETTERS, 163, replace=TRUE), sample(1:1000, 163, replace=FALSE), sep=''),
Group=c(rep('C',10),rep('FH',10),rep('I',19),rep('IF',42),rep('NA',14),rep('NF',42),rep('NI',15),rep('NS',10),rep('PGMC4',1)),
Value=rnorm(n=163))
#I don't want to compare PGMC4 cause I have only onw sample
groups <- as.character(unique(mydf$Group[which(mydf$Group!="PGMC4")]))
#function to make combinations of groups without repeating pairs, and avoiding self-combinations
expand.grid.unique <- function(x, y, include.equals=FALSE){
x <- unique(x)
y <- unique(y)
g <- function(i){
z <- setdiff(y, x[seq_len(i-include.equals)])
if(length(z)) cbind(x[i], z, deparse.level=0)
}
do.call(rbind, lapply(seq_along(x), g))
}
#all pairs I want to compare
combs <- as.data.frame(expand.grid.unique(groups, groups), stringsAsFactors=FALSE)
head(combs)
my.comps <- as.data.frame(t(combs), stringsAsFactors=FALSE)
colnames(my.comps) <- NULL
rownames(my.comps) <- NULL
#pairs I want to compare in list format for stat_compare_means
my.comps <- as.list(my.comps)
head(my.comps)
pdf(file="test.pdf", height=20, width=25)
print(#or ggsave()
ggplot(mydf, aes(x=Group, y=Value, fill=Group)) + geom_boxplot() +
stat_summary(fun.y=mean, geom="point", shape=5, size=4) +
scale_fill_manual(values=myPal) +
ggtitle("TEST TITLE") +
theme(plot.title = element_text(size=30),
axis.text=element_text(size=12),
axis.text.x = element_text(angle=45, hjust=1),
axis.ticks = element_blank(),
axis.title=element_text(size=20,face="bold"),
legend.text=element_text(size=16)) +
stat_compare_means(comparisons=my.comps, method="wilcox.test", label="p.signif", size=14) + #WHY DOES hide.ns=TRUE NOT WORK??? WHY DOES size=14 NOT WORK???
stat_compare_means(method="kruskal.test", size=14) #GLOBAL COMPARISON ACROSS GROUPS (HOW TO LEAVE PGMC4 OUT OF THIS??)
)
dev.off()
##############################
MWE 将生成以下箱线图:
问题是:
1- 如何使 hide.ns=TRUE 工作?
2- 如何增加 * 的大小?
3- 如何从 kruskal.test 比较中排除一个组?
4- ggpubr 使用的 * 约定是什么,显示的 p 值是否经过调整?
非常感谢!!
编辑
另外,做的时候
stat_compare_means(comparisons=my.comps, method="wilcox.test", p.adjust.method="BH")
我没有获得与做时相同的 p 值
wilcox.test(Value ~ Group, data=mydf.sub)$p.value
其中 mydf.sub 是 mydf 的一个子集(),用于 2 个组的给定比较。
ggpubr 在这里做什么?它是如何计算 p.values 的?
编辑 2
请帮忙,解决方案不必与 ggpubr 一起(但它必须与 ggplot2 一起),我只需要能够隐藏 NS 并使星号的大小更大,以及与 wilcox.test() + p.adjust(method"BH") 相同的 p 值计算。
谢谢!
【问题讨论】:
-
1.确实是的。似乎是一个错误; 2. 不知道; 3. 使用
stat_compare_means(data=mydf[ mydf$Group != "PGMC4", ],aes(x=Group, y=Value, fill=Group), size=5)4. 将结果与pairwise.wilcox.test(mydf$Value, mydf$Group, p.adjust.method = "none")进行比较 -
我应该如何通知这个错误?你知道它是否有可能很快得到解决?非常感谢!
-
自己绘制所有的东西,例如使用
library(ggsignif);geom_signif()和注释。看这里最后一个答案:stackoverflow.com/questions/17084566/… -
你能把它发展成一个答案吗?使用 ggsignif 的 geom_signif() 我似乎不知道如何删除 NS 比较,如何更改 ** 的大小,以及如何放置括号以使它们不重叠(就像 ggpubr 一样)...所以我在同一点
-
请任何人都可以在这里阐明一下吗?非常感谢!
标签: r ggplot2 boxplot p-value ggpubr