title: How to order dates on x-axis with ggplot
body: <p>I am trying to use <code>ggplot</code> to plot a grouped barplot. I noticed that the date variable is considered as factor and while plotting R changes its order randomly. </p>
  
  <p>I tried converting the date using <code>as.date(X,format="%m/%d/%Y")</code> but with no help.</p>
  
  <p>Here is my code,</p>
  
  <pre><code>A&lt;-data.frame(A)
  A$Date&lt;-as.Date(A$Date, format = "%m/%d/%Y")
  Name=XYZ
  B&lt;-A[c(1,2,5,6)]
  C&lt;-melt(B,id.vars='Date')
  C$Date&lt;-as.Date(C$Date, format = "%m/%d/%Y")
  ggplot(C,aes(x=Date,y=value))+
   geom_bar(aes(fill = variable), position = "dodge", stat="identity")+
   scale_fill_brewer(palette="Set1")+
   labs(x='Date',y='%Return')+ggtitle('Model')+
   theme(plot.title = element_text(hjust = 0.5))+
   theme(axis.text.x = element_text(angle = 90, hjust = 1, size=7,color="Black"))+
   theme(legend.position = 'bottom')+
   theme(legend.text=element_text(size=8))+coord_cartesian( ylim=c(-6, 6))
  </code></pre>
  
  <p>Before converting <code>Date</code> to the proper date format I got the below output but without the order of <code>Date</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/n73wj.png" alt="enter image description here">!</p>
  
  <p>After <code>Date</code> conversion, the output changes drastically:</p>
  
  <p><img src="https://i.stack.imgur.com/AGsq7.png" alt="enter image description here">!</p>
  
  <p>Not sure what I am missing out on.</p>
  
  <p>Thanks in advance!</p>