参考:Add P-values and Significance Levels to ggplots
生物学的强烈推荐看看Y叔的公众号里的统计相关的文章,非常的基础和实用。
统计
- Five things biologists should know about statistics
- 什么是T检验
- 富集基因之注释缺失
- 落入窠臼
- 你昨天才做的分析,可能是几年前的结果!
- 掐架的额外收获
- boxplot
- 如何告别单身
- 主成分分析
- 一文解决RT-PCR的统计分析
代码例子:
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