title: Sorting the values while using geom_bar(stat="identity")
body: <h3>Problem</h3>
  
  <p>I'm using <code>ggplot2</code>, and I am currently stuck at the following problem. I have the following dataset, which can be reproduced.</p>
  
  <pre><code>library(tidyverse)
  TestDF = data.frame(Effect1 = rnorm(100, 10, 1), Effect2 = rnorm(100, 5, 1)) %&gt;% 
    arrange(Effect1) %&gt;% mutate(IDs = 1:100) %&gt;% 
    melt(measure.vars = 1:2 , variable.name = "Effects") 
  </code></pre>
  
  <p>Since I would like it to be plotted with <code>x</code> sorted according to the values of <code>Effect1</code>, I have put <code>arrange(Effect1)</code> to the dataframe. Then I plotted using the following code:</p>
  
  <pre><code>ggplot(TestDF, aes(IDs, y=value, fill=Effects)) + 
    geom_bar(stat="identity", alpha = .7)
  </code></pre>
  
  <p>And the problem I have encountered : the plot has "general" trend of increasing values of <code>Effect1</code> (as we see from the left to the right), but is never sorted exactly according to the values of <code>Effect1</code>. </p>
  
  <hr>
  
  <h3>What I tried</h3>
  
  <p>I have tried </p>
  
  <pre><code>TestDF$IDs = factor(TestDF$IDs, levels=1:100)
  </code></pre>
  
  <p>but it never fixed my problem. Any other solutions (or bypasses)?</p>