title: Adjusting y axis origin for stacked geom_bar in ggplot2
body: <p>I want to plot stacked bar plot with ggplot2 and am having difficulty getting the colour mapping and stack order right.  The following example has been developed from <a href="https://stackoverflow.com/a/13423600/1156245">this SO answer</a> to achieve a non-zero y-axis origin, but as you can see it creates other problems.  The colours don't map properly and the plot order is wrong.  Grateful for any pointers on the best way to handle this.  The desired output should scale colours as per the factor levels for <code>rating</code>, with colours in the order specified.</p>
  
  <pre><code>require(ggplot2)
  d = data.frame(grp = rep(c('A','B'), each = 4), 
                 rating = rep(c('bad','poor','ok','good'), 2),
                 value = c(15,45,35,5,5,15,55,30), stringsAsFactors = F)
  
  if(require(reshape2)) reshape2::dcast(d, grp ~ rating) # show structure
  
  d$rating = ordered(d$rating, levels=c('bad','poor','ok','good'))
  d$grp = ordered(d$grp, levels=c('B','A'))
  
  # split datsets so we can plot 'negative' bars
  d1 = subset(d, rating %in% c('ok','good'))
  d2 = subset(d, rating %in% c('poor','bad'))
  
  ggplot() + 
    geom_bar(data = d1, aes(x=grp, y=value, fill=rating), stat='identity', position='stack') + 
    geom_bar(data = d2, aes(x=grp, y=-value, fill=rating), stat='identity', position='stack') + 
    scale_fill_manual(values=c('red','pink','lightgreen','green')) +
    geom_line(data=d1, aes(x=c(.5,2.5), y=c(0,0)), size=2, linetype='dashed') +
    coord_flip()
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/KqeP0.png" alt="enter image description here"></p>