title: Creating a grouped bar plot in R with bars unarranged
body: <p>I want to create a grouped bar plot. I realized that the bars are arranged based on the alphabetical order of the items in the legend. How can I make the code generate the graph without rearranging the bars in the alphabetical order?</p>
  <pre><code>library(ggplot2)
  
  # creating dataset
  Year &lt;- c(rep(&quot;2012&quot; , 3) , rep(&quot;2013&quot; , 3) , rep(&quot;2014&quot; , 3) , rep(&quot;2015&quot; , 3) )
  Legend &lt;- rep(c(&quot;A&quot; , &quot;X&quot; , &quot;E&quot;) , 4)
  Count &lt;- abs(rnorm(12 , 0 , 15))
  data &lt;- data.frame(Year,Legend,Count)
  
  # Grouped barplt
  ggplot(data, aes(fill=Legend, y=Count, x=Year)) + 
    geom_bar(position=&quot;dodge&quot;, stat=&quot;identity&quot;)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Kkrsn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kkrsn.png" alt="enter image description here" /></a></p>
  <p>As seen in the image, the bars have been arranged in the order A, E, X - but i want it in the order as it is in the table (A, X, E).</p>
  <p>I hope to get some help with this issue. Thank you.</p>