ggplot的boxplot添加显著性 | Add P-values and Significance Levels to ggplots

Posted leezx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ggplot的boxplot添加显著性 | Add P-values and Significance Levels to ggplots相关的知识,希望对你有一定的参考价值。

参考:Add P-values and Significance Levels to ggplots

 

代码例子:

options(repr.plot.width=7, repr.plot.height=6)
# facet boxplot
bp <- ggplot(expr_data2, aes(x=group, y=expression, fill=NA)) + 
  geom_boxplot(outlier.size=NA, size=0.01, outlier.shape = NA) + 
  geom_jitter(width = 0.3, size=0.01, aes(color=cluster)) +
  # + geom_boxplot( + 
  facet_grid( cluster ~ gene, switch="y") + # , scales = "free"
  theme_bw() + 
  stat_compare_means(aes(group = group, label = ..p.signif..), label.x = 1.3,label.y = 1.3, 
                     method = "wilcox.test", hide.ns = T) + # label = "p.format",
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
  labs(x = "", y = "", title = "") +
  theme(panel.spacing=unit(.3, "lines"),panel.border = element_rect(color = "black", fill = NA, size = 0.2)) +
  theme(axis.ticks.x = element_blank(), axis.ticks = element_line(size = 0.1), 
        axis.text.x  = element_text(face="plain", angle=90, size = 8, color = "black", vjust=0.5),
        axis.text.y  = element_text(face="plain", size = 4, color = "black"),
        axis.title =element_text(size = 12)) +
  theme(strip.background = element_rect(fill = "gray97", color = NA))+
  theme(legend.position = "none") +
  theme(strip.placement = "outside", strip.text.x = element_text(face="italic", size = 11),
          strip.text.y = element_text(face="plain", size = 11)) +
  scale_y_continuous(position="right", limits = c(-0.5,1.5)) +
  scale_fill_manual(values=brewer.pal(8,"Set2")[c(2,3,7,1,5,6)]) +
  scale_color_manual(values=brewer.pal(8,"Set2")[c(2,3,7,1,5,6)])
bp

  

以上是关于ggplot的boxplot添加显著性 | Add P-values and Significance Levels to ggplots的主要内容,如果未能解决你的问题,请参考以下文章

ggplot2 画图随笔

R语言可视化分面图单变量分组多水平t检验并指定参考水平可视化单变量分组多水平分面箱图(faceting boxplot)并添加显著性水平指定显著性参考水平添加抖动数据点

R语言可视化分面图多变量分组嵌套多水平t检验并指定参考水平可视化多变量分组嵌套多水平分面箱图(faceting boxplot)并添加显著性水平指定显著性参考水平

R语言可视化分面图假设检验单变量分组多水平t检验并指定参考水平可视化单变量分组多水平分面箱图(faceting boxplot)并添加显著性水平指定显著性参考水平

R语言ggplot2可视化分组箱图并且在箱图中添加每个分组的均值将每个箱图中的分组均值使用线条连接起来(Add a line connecting Mean Values on Boxplot)

R语言可视化分面图多变量分组多水平t检验可视化多变量分组多水平分面箱图(faceting boxplot)并添加显著性水平在标签和绘图上边框之间添加15%的空格