barplotN<-function(x, y, err.bars="ci", col="grey", length=0.05,tick=F, las=2, ylab=names(y), xlab = "Group",...){ x<-as.factor(x) par(mar=c(5,5,2,2)) means<-tapply(y, x, mean) if (err.bars=="se") int<-sqrt(tapply(y, x, var)/(tapply(y, x, length)-1)) if (err.bars=="ci") {int<-sqrt(tapply(y, x, var)/(tapply(y, x, length)-1))*qt(0.975, tapply(y, x, length)-1)} if (err.bars!="range") { maxs<-means+int mins<-means-int } if (err.bars=="range") { maxs<-tapply(y, x, max) mins<-tapply(y, x, min) } aa<-barplot(means, ylim=c(min(c(mins,0)), max(maxs+1)), # -abs(0.1*min(mins)) +abs(0.1*max(maxs)) xaxt='n', col=col, xlab=xlab, ylab=ylab, las=las) axis(1, aa, labels=levels(x), xlab=NA, tick = tick) arrows(aa, y0=mins, y1=maxs, code=3, angle=90, length = 0.05) }