# Set your working directory # then remove the "#" in front of the setwd line #setwd("your working directory here") # Read the data myData<-read.csv("growth.csv") # Extract the useful information mean.gain<-tapply(myData$gain, list(myData$supplement,myData$diet), mean) sd.gain<-tapply(myData$gain, list(myData$supplement,myData$diet), sd) n.gain<-tapply(myData$gain, list(myData$supplement,myData$diet), length) # The main figure mids<- barplot(mean.gain,beside=T, xlab="Feed type", ylab="Weight gain", ylim=c(0,35), col=grey(c(0,0.3,0.6,1))) # The error bar arrows(mids, mean.gain+sd.gain, mids, mean.gain-sd.gain, angle=90, code=3, length=0.1) # The little text at the bottom text(mids,2,paste(n.gain),col=c("white",rep("black",3))) # The legend legend("topright",legend=rownames(mean.gain),fill=grey(c(0,0.3,0.6,1)))