在双向anova

时间:2017-10-07 21:50:16

标签: r ggplot2 annotations geom-text tukeyhsd

我试图用双向anova绘制与TukeyHSD的重要字母,但只找到了单向anova的信息。我希望在每个组中都有字母进行比较,例如Gene1内和Gene2内。

Link to example plot

创建数据框

Gene<-c("Gene1","Gene2","Gene1","Gene2")
count1<-c(12,14,16,34)
count2<-c(4,7,9,23)
count3<-c(36,22,54,12)
count4<-c(12,24,35,23)
Species<-c("A","A","B","B")
df<-data.frame(Gene,count1,count2,count3,count4,Species)
df

mean1<-mean(as.numeric(df[1,][c(2,3,4,5)]))
mean2<-mean(as.numeric(df[2,][c(2,3,4,5)]))
mean3<-mean(as.numeric(df[3,][c(2,3,4,5)]))
mean4<-mean(as.numeric(df[4,][c(2,3,4,5)]))
Gene1SpeciesA.stdev<-sd(as.numeric(df[1,][c(2,3,4,5)]))
Gene2SpeciesA.stdev<-sd(as.numeric(df[2,][c(2,3,4,5)]))
Gene1SpeciesB.stdev<-sd(as.numeric(df[3,][c(2,3,4,5)]))
Gene2SpeciesB.stdev<-sd(as.numeric(df[4,][c(2,3,4,5)]))

ToPlot<-c(mean1,mean2,mean3,mean4)

cols = c(2,3,4,5)
df1  = transform(df, mean=rowMeans(df[cols]), sd=apply(df[cols],1, sd))


ggplot(df1, aes(x=as.factor(Gene), y=mean, fill=Species)) +
 geom_bar(position=position_dodge(), stat="identity", colour='black') +
 geom_errorbar(aes(ymin=mean-sd, ymax=mean+sd), 
width=.2,position=position_dodge(.9))

0 个答案:

没有答案