在具有多个组的箱图中用ggplot2表示显着性

时间:2017-12-15 21:19:50

标签: r plot ggplot2

我有以下用ggplot2和ggpubr制作的情节。我想指出VaD +和HC之间的重要性。我想将p值更改为星号。我想我应该使用symnum.args,但是当我尝试它时,我没有任何改变。

myplot <- ggplot(my.data, aes(x = DX, y = CC, fill=DX)) + geom_boxplot() + ggtitle("Corpus Collasum") + theme(text=element_text(size = 16), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = element_line(colour = "black"), plot.title = element_text(lineheight=.8, face="bold", hjust=0.5)) + scale_y_continuous(name = bquote('Volume in'~mm^3)) + scale_x_discrete(name = "Diagnosis", labels = c("AD","HC","VaD-","VaD+")) + scale_fill_brewer(palette="OrRd", name="Diagnosis", labels=c("AD","HC","VaD-","VaD+")) + geom_jitter(width = 0)
cmpr <- list(c("VaDD","HC"), c("AD","VaDD"))
myplot + stat_compare_means(comparisons = cmpr, tip.length=0.01, symnum <- list(cutpoints = c(0, 0.0001, 0.001, 0.01, 0.05, 1), symbols = c("****", "***", "**", "*", "ns")))

基本上我想用符号替换数字p值。

Here是数据。

this plot

1 个答案:

答案 0 :(得分:2)

@dww(使用*.elb.amazonaws.com)给出的解决方案是正确的:

label = "p.signif"

enter image description here

编辑:我修改了cmpr <- list(c("VaD+","HC"), c("AD","HC")) myplot + stat_compare_means(comparisons = cmpr, tip.length=0.01, label = "p.signif", symnum.args = list(cutpoints = c(0, 0.0001, 0.001, 0.01, 0.05, 1), symbols = c("****", "***", "**", "*", "ns"))) ,因为此功能似乎忽略了stat_compare_means

symnum.args

enter image description here