ggpubr计算的P值存有问题被统计大佬诟病,无法使用bonferroni的方法进行多重,比较烦发现GitHub https://github.com/kassambara/rstatix 这个叫rstatix的包可以搞
上才艺,library搞起
library(ggpubr)
library(rstatix)
#导入数据
rt=read.table(inputFile,sep="\t",header=T,check.names=F)
数据长这样

这个包的操作让我很迷茫pairwise_t_test 这个函数本上就是多重比较
x=colnames(rt)[2]
y=colnames(rt)[3]
colnames(rt)=c("id","Type","Expression")
#设置比较租
group=levels(factor(rt$Type))
rt$Type=factor(rt$Type, levels=group)
comp=combn(group,2)
my_comparisons=list()
for(i in 1:ncol(comp)){my_comparisons[[i]]<-comp[,i]}
###自信的打脸操作,看了源码发现pairwise_t_test可以进行多重比较,所以自信的按照添加p值。
stat.test <- rt %>%
pairwise_t_test(formula =Expression~Type ,comparisons = my_comparisons) %>% ##需要一个比较组才能做
adjust_pvalue() %>%
add_significance("p.adj")%>%
add_xy_position(x = "Type", dodge = 0.8)
成功了,它有在ggplot2的接口,stat_pvalue_manual函数所以我直接用了

t_test这个函数我看是两者比较,但是很迷。它会多重比较让我质疑pairwise_t_test的意义
stat.test1 <- rt %>%
t_test(Expression ~ Type) %>%###神奇的函数,把pairwise_t_test整的我都看不懂了
adjust_pvalue(method = "bonferroni") %>%
add_significance("p.adj")%>%
add_xy_position(x = "Type", dodge = 0.8)
stat.test$p.adj <- paste0('p = ',stat.test1$p.adj)##添加P=的符号

绘制图
#绘制boxplot
boxplot=ggboxplot(rt, x="Type", y="Expression", color="Type",
xlab=x,
ylab=y,
legend.title=x,
add = "jitter")+ stat_pvalue_manual(
stat.test, label = "p.adj",#label函数可以label = 'p.adj.signif'会出现*图
tip.length = 0.02,
step.increase = 0.05
) +
scale_y_continuous(expand = expansion(mult = c(0.05, 0.1)))

懂行告诉我这两个参数的差异,我只看到的校正P的不同,不理解具体,请统计大神来科普一下