0

I'm trying to plot the significance letters with TukeyHSD, in a two-way anova, but have only found information for a one way anova. I'd like to have letters for comparisons within each group, such as within Gene1 and within Gene2.

Link to example plot

create dataframe

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))
zx8754
  • 52,746
  • 12
  • 114
  • 209
Canteen9
  • 11
  • 3
  • It make it much easer for us to help you if you produce a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) (MCVE). I emphasize _minimal_, a small excerpt of your data and the expected outcome. You can find detailed information on how to create a goo MCVE for R [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Eric Fail Oct 08 '17 at 12:32
  • Thanks I added in another code set seen online that should be minimal enough to get the idea – Canteen9 Oct 08 '17 at 17:05
  • Thanks. I am still kinda not sure what you are looking for. Is is something like [this](https://stackoverflow.com/a/18777045/1305688) or possibly [this](https://stackoverflow.com/a/44713000/1305688)? – Eric Fail Oct 08 '17 at 21:36
  • Yes its kinda like those, those examples are comparing across all treatments. What I'd like to do it use the multcompView and generate letters within each category such as the graph below. Comparisons would be made within the 3 cylinder only, then another anova between the 4 and another anova between the 5.Rather than how all the treatments are compared [Example graph](https://www.nature.nps.gov/ParkScience/Graphics/vol_32_1/Best_8_Embed_3.gif) – Canteen9 Oct 08 '17 at 22:03

0 Answers0