打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
绘图专题 | 使用ggsignif添加显著性标签

承接前文,建议先读

使用ggpubr绘制箱式图(基础篇)

ggsci发表级配色

使用ggpubr绘制箱式图(进阶篇一)

前文说到,ggpubr绘制的箱式图中可以方便的添加显著性信息,其实内部调用了ggsignif包:

Enrich your 'ggplots' with group-wise comparisons. This package provides a single layer geom_signif which can calculate the significance of a difference between groups and add the annotation to the plot in a single line.

但是这个包最近一次的更新是在2017年...

  1. # 安装加载

  2. p_load_gh('const-ae/ggsignif')

使用ggsignif绘制带errobar的箱体图:

  1. p_load(ggsci, ggplot2)

  2. data(ToothGrowth)

  3. colors = pal_lancet('lanonc')(9)[1:3]    # 颜色设置

  4. ToothGrowth$dose = as.factor(ToothGrowth$dose)    # 分组转换为因子型

  5. # ggplot2绘图

  6. p = ggplot(ToothGrowth, aes(x = dose, y = len)) +

  7.    #geom_boxplot(width = 0.7) +     # add boxplot

  8.    scale_colour_manual(values = colors) +

  9.    theme_classic() + theme(legend.position = 'top') +

  10.    # 添加 errorbar

  11.    stat_boxplot(geom = 'errorbar', color = colors, width = 0.4, size = 1) +

  12.    geom_boxplot(aes(color = dose), width = 0.7)

  13. my_comparisons = list(c('0.5', '1'), c('0.5', '2'))

  14. p + geom_signif(comparisons = my_comparisons, step_increase = 0.2)


注意,这里 color=group,需要设置在 geom_boxplot中,而不是在 ggplot中,否则会报错:

https://github.com/const-ae/ggsignif/issues/42

Error in check.length(gparname) :'gpar' element 'fontsize' must not be length 0

geom_signif 默认使用wilcox.test进行两组间差异表达分析,可以设置 test='t.test' 为T检验,而对于多组间差异分析并没有默认的支持:

the name of the statistical test that is applied to the values of the 2 columns (e.g. ‘t.test‘, ‘wilcox.test‘ etc.). If you implement a custom test make sure that it returns a list that has an entry called ‘p.value‘.

Please note that the package is only designed to support 2 way comparisons (unlike the original intend of an anova), so you might want to compute the individual p-values separately and then use the annotations parameter to draw them.

https://github.com/const-ae/ggsignif/issues/37

所以如果想要使用类似anova的多组间差异表达分析,需要先单独计算,然后使用 annotations 添加到图中:

  1. aov_res = summary(aov(len ~ dose, data = ToothGrowth))[[1]]

p + geom_signif(comparisons = my_comparisons, y_position = c(32, 37)) +
annotate('text', x = '1', y = 45, label = paste('Anova, p = ', signif(aov_res[1,5], 3)), size = 4)


近期,很多小伙伴询问生信控课程的事情

TCGA数据挖掘课程:

这次一定带你进入生信分析的大门

GEO数据挖掘课程:

文献模拟 | 4分纯生信文章看过来!

 有想购买的也被婉拒,因为...


元旦有活动!有活动!


生信控送福利,前所未有


12月31日00:00准时发布


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
R ggplot和ggsignif箱线图添加显著性差异标识
一图胜千言-箱式图+显著性差异更好看
R绘图:ggeconodist,基于ggplot2的另类箱图
ggplot2|从0开始绘制箱线图
R基础知识及快速检阅你的数据
R语言 ggplot绘图不显示p值并报错 containing missing values (geom_signif).
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服