df = data.frame(A =c(7.76,7.71,8.43,8.47,10.3,6.67,11.73,5.78,6.61,6.97),
B =c(12.14,13.6,14.42,13.85,17.53,14.16,14.94,13.01,14.18,17.72),
C =c(10.85,8.59,7.19,9.36,9.59,8.81,8.22,9.95,11.26,8.68))
数据融合
data =melt(df)colnames(data)=c('group','ATP_expr')
as.factor(data$group)
描述性统计
describeBy(data$ATP_expr,data$group)
方差分析
fit =aov(ATP_expr~group,data)
正态性检验
res = fit$residuals
ggqqplot(res)
方差齐次性检验
leveneTest(ATP_expr~group,data)
两两比较
summary(fit)
Tu =TukeyHSD(fit) # 多重比较
p = Tu$group[,4]
p.signif =ifelse(p <0.05,ifelse(p <0.01,ifelse(p <0.001,'***','**'),'*'),'ns')
可视化
comp =list(c('A','B'),c('A','C'),c('B','C'))ggboxplot(data, x ="group", y ="ATP_expr",
fill ="group",
palette ="jco",
bxp.errorbar = T,
add ='jitter',short.panel.labs = F)+geom_signif(comparisons = comp,
y_position =c(16,20,18),
annotations =unname(p.signif))
2.双因子方差分析
方差分析
ToothGrowth$dose = as.factor(ToothGrowth$dose)
fit =aov(data = ToothGrowth,len~supp*dose)
正态性检验
res = fit$residuals
ggqqplot(res)
方差齐次性检验
leveneTest(len~supp*dose,ToothGrowth)
两两比较
summary(fit)TukeyHSD(fit)
Tu =TukeyHSD(fit) # 多重比较
all_pvalue = Tu$`supp:dose`
rownames(all_pvalue)
p = all_pvalue[c(2,4,11,7,9,14),4]
p.signif =ifelse(p <0.05,ifelse(p <0.01,ifelse(p <0.001,'***','**'),'*'),'ns')
可视化
annotation <- data.frame(supp=rep(c('OJ','VC'),each =3),
start=c("0.5","0.5",'1'),
end=c('1','2','2'),
y =c(34,38,36),
label=unname(p.signif))
ggboxplot(ToothGrowth, x ="dose", y ="len",
fill ="dose",
bxp.errorbar = T,
add ='jitter',
palette =c("#00AFBB","#FC4E07","#E7B800"), # 自定义色彩
facet.by ="supp",short.panel.labs = FALSE,xlab ='')+geom_signif(data = annotation,aes(xmin=start, xmax=end, annotations=label, y_position=y),
manual=TRUE)
条形图+误差棒
ggbarplot(ToothGrowth, x ="dose", y ="len",
fill ="dose",
add ='mean_se',
palette =c("#00AFBB","#FC4E07","#E7B800"), # 自定义色彩
facet.by ="supp",short.panel.labs = FALSE,xlab ='')+geom_signif(data = annotation,aes(xmin=start, xmax=end, annotations=label, y_position=y),
manual=TRUE)