title: Reordering bars in ggplot2 bar graph using only one variable (w/o value or ranking)?
body: <p>I'd like to ra-arrange the bars of my ggplot bar chart - and there is quite a number of similar entries here on stackoverflow (e.g. <a href="https://stackoverflow.com/questions/5208679/order-bars-in-ggplot2-bar-graph">here</a>).</p>
  
  <p>However, the question I have is: can you do this with only one variable (the one used for the bar graph) by telling ggplot not to sort alphabetically by labels but sort by take the count of identical labels as the value of interest.</p>
  
  <p>In my case, I have survey data on the question of which political party champions a certain issue/ is the most competent in a given issue area.</p>
  
  <pre><code>respondent-id    competence
  1                "Party A"
  2                "Party A"
  3                "Party B"
  4                "Party B"
  5                "Party B"
  6                "Party C"
  </code></pre>
  
  <p>What ggplot would do now is a bar chart with the 2nd-highest first (party A), highest second (party B) and lowest last (party C). But how do I tell ggplot to take the count into account (2:3:1 --> place party B first)?</p>
  
  <p>I tried several ways as suggested <a href="https://stackoverflow.com/questions/5208679/order-bars-in-ggplot2-bar-graph">here</a>, but that didn't solve the problem: most of them included a position-variable which would tell ggplot "assign party B first place". I also tried to <code>reorder()</code> simply by "competence", with no success. Finally, I could assign different prefixes to the parties ("1_party_B", "2_...") but that would really tedious work.</p>
  
  <pre><code>ggplot(MyData, aes(x=competence,y=(..count..))) + geom_bar()
  </code></pre>
  
  <p>Also, I have a NA-bar in my bar chart, and <code>MyData[,c("competence")]</code> doesn't seem to do the trick. But that's another story.</p>
  
  <p>Thanks in advance!</p>