承接前文,建议先读
前文说到,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年...
# 安装加载
p_load_gh('const-ae/ggsignif')
使用ggsignif绘制带errobar的箱体图:
p_load(ggsci, ggplot2)
data(ToothGrowth)
colors = pal_lancet('lanonc')(9)[1:3] # 颜色设置
ToothGrowth$dose = as.factor(ToothGrowth$dose) # 分组转换为因子型
# ggplot2绘图
p = ggplot(ToothGrowth, aes(x = dose, y = len)) +
#geom_boxplot(width = 0.7) + # add boxplot
scale_colour_manual(values = colors) +
theme_classic() + theme(legend.position = 'top') +
# 添加 errorbar
stat_boxplot(geom = 'errorbar', color = colors, width = 0.4, size = 1) +
geom_boxplot(aes(color = dose), width = 0.7)
my_comparisons = list(c('0.5', '1'), c('0.5', '2'))
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
添加到图中:
aov_res = summary(aov(len ~ dose, data = ToothGrowth))[[1]]
近期,很多小伙伴询问生信控课程的事情
TCGA数据挖掘课程:
GEO数据挖掘课程:
有想购买的也被婉拒,因为...
元旦有活动!有活动!
生信控送福利,前所未有
12月31日00:00准时发布
联系客服