title: Maintain order of geom_bar() fill with ggplot2
body: <p>I have a sediment core dataset that I would like to portray graphically with geom_bar() in ggplot2 and fill with a variable. The fill variable alternates with every other level of fill, but with the new version (2.2.1) of ggplot2 I cannot maintain this fill pattern. This is discussed <a href="https://github.com/tidyverse/ggplot2/issues/1472" rel="nofollow noreferrer">here</a> but I cannot find a workable solution.</p>
  
  <pre><code>library(ggplot2)
  site&lt;-c(rep('a',14),rep('z',8))
  sedcore&lt;-1
  fill&lt;-c("y","n","y","n","y","n","y","n","y","n","y","n","y","n","y","n","y","n","y","n","y","n")
  df &lt;- data.frame(cbind(site,sedcore,fill))
  
  ggplot(df, aes(x=site, y=sedcore, fill=fill)) + geom_bar(position="stack",stat="identity",colour="black",size=0.35)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/XRQIQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XRQIQ.png" alt="Order not maintained"></a></p>
  
  <p>The newest version of ggplot does NOT maintain the order of the dataframe</p>
  
  <p>If I load ggplot2 version 2.1 the order of the dataframe is maintained:</p>
  
  <pre><code>library(devtools)
  install_version("ggplot2", version = "2.1.0", repos = "http://cran.us.r-project.org") 
  library(ggplot2)
  
  ggplot(df, aes(x=site, y=sedcore, fill=fill)) + geom_bar(position="stack",stat="identity",colour="black",size=0.35)
  </code></pre>
  
  <p>The same exact code now maintains the order:
  <a href="https://i.stack.imgur.com/cbz9s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cbz9s.png" alt="Order maintained"></a></p>
  
  <p>Please advise on how to maintain order from dataframe. I have tried reordering my dataframe and different position and stack terms, but cannot figure this out.</p>
  
  <p>Thanks in advance for any help.</p>