title: ggplot2 - Bars non-aligned to error bars
body: <p>I am trying to plot error bars over bars in R using ggplot2. The position of the bars is ok, however the error bars are misaligned, overlapped. Please take a look at the example below:</p>
  
  <pre><code>library(ggplot2)
  
  df = structure(list(variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
  2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 
  4L, 4L), .Label = c("Stage1", "Stage2", "Stage3", "Stage4"), class = "factor"), 
      scenario = c("A", "A", "A", "B", "B", 
      "B", "A", "A", "A", "B", "B", 
      "B", "A", "A", "A", "B", "B", 
      "B", "A", "A", "A", "B", "B", 
      "B"), Period = c("2011-2040", "2041-2070", "2071-2100", 
      "2011-2040", "2041-2070", "2071-2100", "2011-2040", "2041-2070", 
      "2071-2100", "2011-2040", "2041-2070", "2071-2100", "2011-2040", 
      "2041-2070", "2071-2100", "2011-2040", "2041-2070", "2071-2100", 
      "2011-2040", "2041-2070", "2071-2100", "2011-2040", "2041-2070", 
      "2071-2100"), value = c(-1, -2, -3, -1, -3, -4, -2, -1, -1, 
      -2, -1, -1, -5, -6, -6, -5, -6, -7, -1, -1, -1, -1, -1, -1
      ), error = c(0.861817443828852, 0.948522930371594, 0.916295430216828, 
      1.09513465405609, 0.967022228830058, 0.962082007787887, 0.327433241996297, 
      0.296270630257992, 0.241564623986049, 0.324799025797241, 
      0.287300168855865, 0.321141699334506, 0.448402583575847, 
      0.329720917851603, 0.296149789779728, 0.423049544646902, 
      0.320807147599275, 0.286926161100617, 0.46555636533774, 0.494769057825624, 
      0.498445009296978, 0.490846868961772, 0.478102139172148, 
      0.47821442683311), ymin = c(-1.86181744382885, -2.94852293037159, 
      -3.91629543021683, -2.09513465405609, -3.96702222883006, 
      -4.96208200778789, -2.3274332419963, -1.29627063025799, -1.24156462398605, 
      -2.32479902579724, -1.28730016885586, -1.32114169933451, 
      -5.44840258357585, -6.3297209178516, -6.29614978977973, -5.4230495446469, 
      -6.32080714759928, -7.28692616110062, -1.46555636533774, 
      -1.49476905782562, -1.49844500929698, -1.49084686896177, 
      -1.47810213917215, -1.47821442683311), ymax = c(-0.138182556171148, 
      -1.05147706962841, -2.08370456978317, 0.0951346540560851, 
      -2.03297777116994, -3.03791799221211, -1.6725667580037, -0.703729369742008, 
      -0.758435376013951, -1.67520097420276, -0.712699831144135, 
      -0.678858300665494, -4.55159741642415, -5.6702790821484, 
      -5.70385021022027, -4.5769504553531, -5.67919285240072, -6.71307383889938, 
      -0.53444363466226, -0.505230942174376, -0.501554990703022, 
      -0.509153131038228, -0.521897860827852, -0.52178557316689
      )), .Names = c("variable", "scenario", "Period", "value", 
  "error", "ymin", "ymax"), class = "data.frame", row.names = c(NA, 
  -24L))
  
  
  ggplot(data=df, aes(x=Period, y=value)) +
       geom_bar(aes(fill=variable), position='dodge', stat="identity", width=0.75) +
       geom_errorbar(aes(ymin=ymin, ymax=ymax, width=.2)) +
       facet_wrap(~scenario) +
       theme_bw(base_size=16)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/SjuOq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SjuOq.png" alt="enter image description here"></a></p>
  
  <p>As you can see, the error bars are not properly aligned with the data bars. I've also tried a few solutions found on the web, such as:</p>
  
  <pre><code>geom_errorbar(aes(ymin=ymin, ymax=ymax), position = position_dodge(0.9)) 
  </code></pre>
  
  <p>but to no avail.</p>
  
  <p>What is wrong with my ggplot command?</p>