I have been given the below function for creating a boxplot with error bars which works nicely.
However I need to add axis labels and I have been two days trying to figure out where to add code like this
# col=c(2,7),ylab="Relative Fitness",xlab="Block")
error.bars<-function(Response,x1,x2) {
mean.table<-tapply(Response,list(x1,x2),mean)
mean.table[is.na(mean.table)]<-0
var.table<-tapply(Response,list(x1,x2),var)
n.table<-tapply(Response,list(x1,x2),length)
std.errors<-sqrt(var.table/n.table)
std.errors[is.na(std.errors)]<-0
biggest.value<-max(mean.table+std.errors)
bartable<-barplot(mean.table,beside=TRUE,
ylim=c(0,biggest.value+1))
errbar.width<-(max(bartable)-min(bartable))/50
for(i in 1:length(mean.table[,1])) {
for(j in 1:length(mean.table[1,])) {
lines(c(bartable[i,j],bartable[i,j]),
c(mean.table[i,j]-std.errors[i,j],
mean.table[i,j]+std.errors[i,j]))
lines(c(bartable[i,j]-errbar.width,
bartable[i,j]+errbar.width),
c(mean.table[i,j]+std.errors[i,j],
mean.table[i,j]+std.errors[i,j]))
lines(c(bartable[i,j]-errbar.width,
bartable[i,j]+errbar.width),
c(mean.table[i,j]-std.errors[i,j],
mean.table[i,j]-std.errors[i,j]))
}
}
}
any tips greatly appreciated
So apologies for my lack of clarity i'm new to R and this site so unsure how to get message across. My data is pretty straight forward and looks like this. n=3 Blocks,n=33 Lines, n=2 for Sex and my y variable with is Fitness. I've been able to make a boxplot with the function the errorbars function I posted earlier. However all i'm trying to do is add x and y axis labels to the function. Seems easy but I can't figure it out.
head(OzGLM) Block Line Sex Fitness 1 1 3 1 0.6865626 2 1 3 2 0.4874816 3 1 4 1 0.4219811 4 1 4 2 0.3829161 5 1 5 1 0.6071388 6 1 5 2 0.4432990