I am trying to add error bars to my barplot
averg <- aggregate(appxincome,by = list(educ,sex),mean)              
boxplot1 <- barplot(averg$x,
                xlab = "Education",
                ylab = "Income",
                ylim = c(0,100000),
                main = "Averge Income by Education and Gender",
                names.arg = c("Female College", "Female High      School","Female Less Than High School","Male College", "Male High      School","Male Less Than High School"),
                cex.names = 0.5,
                las = 2)                                        
confint(mod1)    
cis <- as.data.frame(confint(mod1)) 
error.bar <- function(x, y, upper, lower=upper, length=0.1,...){
  if(length(x) != length(y) | length(y) !=length(lower) | length(lower) != 
length(upper))
    stop("vectors must be same length")
  arrows(x,y+upper, x, y-lower, angle=90, code=3, length=length, ...)
}
stdevs<-aggregate(appxincome~sex,FUN=sd)
lengths<-aggregate(appxincome~sex,FUN=length)
error.bar(boxplot1,averg[,2], 1.96*stdevs[,2]/lengths[,2])
I am getting an error message about the vector length. Can somebody help me fix this? thanks
 
     
    
