title: How to reorder the labels in a bar graph? [ggplot2]
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5208679/order-bars-in-ggplot2-bar-graph">Order Bars in ggplot2 bar graph</a>  </p>
  </blockquote>
  
  
  
  <p><strong>I edited this considerably after closed. (Thank you Andrie for the advice.)</strong></p>
  
  <p><strong>(1) Problem</strong></p>
  
  <p><img src="https://www2.picturepush.com/photo/a/6934175/640/6934175.png" alt=""></p>
  
  <p>The order of the labels are autumn, spring, summer, winter. How do you make them ordered as spring, summer, autumn, winter?</p>
  
  <p><em>Problem Code</em>:</p>
  
  <pre><code>ssn &lt;- c("spring", "summer", "autumn", "winter")
  cnt &lt;- c(2,4,3,7)
  d &lt;- data.frame(season=ssn, count=cnt)
  library(ggplot2)
  ggplot() + geom_bar(data=d,aes(x=season, y=count))
  </code></pre>
  
  <p><strong>(2) Solution</strong></p>
  
  <p><em>Solution Code</em>:</p>
  
  <pre><code>ssn &lt;- c("spring", "summer", "autumn", "winter")
  ssn &lt;- factor(ssn, level=ssn)
  cnt &lt;- c(2,4,3,7)
  d &lt;- data.frame(season=ssn, count=cnt)
  library(ggplot2)
  ggplot() + geom_bar(data=d,aes(x=season, y=count)) 
  </code></pre>
  
  <p>The 2nd line does the trick.
  <img src="https://www3.picturepush.com/photo/a/6934201/640/6934201.png" alt=""></p>