title: Ordering of R geom_bar plot
body: <p>I have a dataset (1000 IDs, 9 classes) similar to this one:</p>
  
  <pre><code>ID     Class     Value
  1      A         0.014
  1      B         0.665
  1      C         0.321
  2      A         0.234
  2      B         0.424
  2      C         0.342
  ...    ...       ...
  </code></pre>
  
  <p>The <code>Value</code> column are (relative) abundances, i.e. the sum of all classes for one individual equals 1. </p>
  
  <p>I would like to create a ggplot <code>geom_bar</code> plot in R where the x axis is not ordered by IDs but by decreasing class abundance, similar to this one:</p>
  
  <p><a href="https://i.stack.imgur.com/HQhdP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HQhdP.png" alt="enter image description here"></a></p>
  
  <p>In our example, let's say that <code>Class B</code> is the most abundant class across all individuals, followed by <code>Class C</code> and finally <code>Class A</code>, the first bar of the x axis would be for the individual with the highest <code>Class B</code>, the second bar would the individual with the second highest <code>Class B</code>, etc. </p>
  
  <p>This is what I tried:</p>
  
  <pre><code>ggplot(df, aes(x=ID, y=Value, fill=Class)) +
    geom_bar(stat="identity") +
    xlab("") +
    ylab("Relative Abundance\n")
  </code></pre>