title: correcting geom_errorbar position with geom_bar
body: <p>Data here:
  <a href="https://www.dropbox.com/s/ezvky6geggpyryu/heights.csv?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/ezvky6geggpyryu/heights.csv?dl=0</a></p>
  
  <p>I'm trying to adjust the position of the error bars to match the mid-point of the bars.</p>
  
  <p>Any suggestions of how to do this? </p>
  
  <p>I've checked a similar post but it doesn't quite answer my question, since I'm already setting my y position using the function.
  <a href="https://stackoverflow.com/questions/13050516/how-to-make-dodge-in-geom-bar-agree-with-dodge-in-geom-errorbar-geom-point">How to make dodge in geom_bar agree with dodge in geom_errorbar, geom_point</a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>heights&lt;-read.csv("heights.csv",as.is=T)
  heights$line &lt;- factor(heights$line, levels=c("Klein157 (1-3)","Klein157 (4-4)", "Maringa (4-2)", "Maringa (5-6)"))
  
  library("ggplot2")
  library("scales")
  
  ##DATA SUMMARY##
  ##code for data summary from 
  ## http://www.cookbook-r.com/Manipulating_data/Summarizing_data/
  ##    data: a data frame.
  ##   measurevar: the name of a column that contains the variable to be summariezed
  ##   groupvars: a vector containing names of columns that contain grouping variables
  ##   na.rm: a boolean that indicates whether to ignore NA's
  ##   conf.interval: the percent range of the confidence interval (default is 95%)
  
  
  summarySE &lt;- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,
                        conf.interval=.95, .drop=TRUE) {
    require(plyr)
  
    # New version of length which can handle NA's: if na.rm==T, don't count them
    length2 &lt;- function (x, na.rm=FALSE) {
      if (na.rm) sum(!is.na(x))
      else       length(x)
    }
  
    # This does the summary. For each group's data frame, return a vector with
    # N, mean, and sd
    datac &lt;- ddply(data, groupvars, .drop=.drop,
                   .fun = function(xx, col) {
                     c(N    = length2(xx[[col]], na.rm=na.rm),
                       mean = mean   (xx[[col]], na.rm=na.rm),
                       sd   = sd     (xx[[col]], na.rm=na.rm)
                     )
                   },
                   measurevar
    )
  
    # Rename the "mean" column    
    datac &lt;- rename(datac, c("mean" = measurevar))
  
    datac$se &lt;- datac$sd / sqrt(datac$N)  # Calculate standard error of the mean
  
    # Confidence interval multiplier for standard error
    # Calculate t-statistic for confidence interval: 
    # e.g., if conf.interval is .95, use .975 (above/below), and use df=N-1
    ciMult &lt;- qt(conf.interval/2 + .5, datac$N-1)
    datac$ci &lt;- datac$se * ciMult
  
    return(datac)
  }
  
  ##using function to summarise data - RIL4 and Cappelle
  
  summarySE(heights, measurevar="height", groupvars=c("line", "allele"))
  summary.h&lt;-summarySE(heights, measurevar="height", groupvars=c("line", "allele"))
  
  ggplot(summary.h, aes(x=line, y= height, fill=allele)) +
    geom_bar(stat = "identity", position="dodge", show_guide=TRUE) + geom_bar(stat = "identity", position="dodge", color="black", show_guide=FALSE) +
    geom_errorbar(aes(ymin=height-se, ymax=height+se), position="dodge", size=1, width=0.5) +
    ylab("Height (cm)") +
    xlab("") +
    scale_y_continuous(breaks=pretty_breaks(n=6)) +
    coord_cartesian(ylim=c(65,100)) +
    scale_x_discrete(breaks = c("Klein157 (1-3)","Klein157 (4-4)", "Maringa (4-2)", "Maringa (5-6)")) +
    scale_fill_manual(values = c("#56B4E9", "#009E73")) +
    theme(panel.grid.minor.x=element_blank(), panel.grid.major.x=element_blank(),
          plot.title = element_text(lineheight=.4, face="bold"),
          axis.title = element_text(size=25, face="bold", colour="black"), 
          axis.text.y = element_text(size=20, colour="black"),
          axis.text.x = element_text(vjust=0.5, size=20,face="bold", colour="black"),
          strip.text.x =element_text(size=22, face="bold"),
          strip.background=element_rect(colour = "black"),
          legend.text= element_text(size = 22),
          legend.title=element_text(size=18),
          legend.position="top") +
    guides(fill=guide_legend(title=NULL))
  </code></pre>