title: Show percent % instead of counts in charts of categorical variables
body: <p>I'm plotting a categorical variable and instead of showing the counts for each category value.</p>
  
  <p>I'm looking for a way to get <code>ggplot</code> to display the percentage of values in that category. Of course, it is possible to create another variable with the calculated percentage and plot that one, but I have to do it several dozens of times and I hope to achieve that in one command.</p>
  
  <p>I was experimenting with something like </p>
  
  <pre><code>qplot(mydataf) +
    stat_bin(aes(n = nrow(mydataf), y = ..count../n)) +
    scale_y_continuous(formatter = "percent")
  </code></pre>
  
  <p>but I must be using it incorrectly, as I got errors.</p>
  
  <p>To easily reproduce the setup, here's a simplified example:</p>
  
  <pre><code>mydata &lt;- c ("aa", "bb", NULL, "bb", "cc", "aa", "aa", "aa", "ee", NULL, "cc");
  mydataf &lt;- factor(mydata);
  qplot (mydataf); #this shows the count, I'm looking to see % displayed.
  </code></pre>
  
  <p>In the real case, I'll probably use <code>ggplot</code> instead of <code>qplot</code>, but the right way to use <a href="http://had.co.nz/ggplot2/stat_bin.html" rel="noreferrer">stat_bin</a> still eludes me.</p>
  
  <p>I've also tried these four approaches:</p>
  
  <pre><code>ggplot(mydataf, aes(y = (..count..)/sum(..count..))) + 
    scale_y_continuous(formatter = 'percent');
  
  ggplot(mydataf, aes(y = (..count..)/sum(..count..))) + 
    scale_y_continuous(formatter = 'percent') + geom_bar();
  
  ggplot(mydataf, aes(x = levels(mydataf), y = (..count..)/sum(..count..))) + 
    scale_y_continuous(formatter = 'percent');
  
  ggplot(mydataf, aes(x = levels(mydataf), y = (..count..)/sum(..count..))) + 
    scale_y_continuous(formatter = 'percent') + geom_bar();
  </code></pre>
  
  <p>but all 4 give:</p>
  
  <blockquote>
  <pre><code>Error: ggplot2 doesn't know how to deal with data of class factor
  </code></pre>
  </blockquote>
  
  <p>The same error appears for the simple case of </p>
  
  <pre><code>ggplot (data=mydataf, aes(levels(mydataf))) +
    geom_bar()
  </code></pre>
  
  <p>so it's clearly something about how <code>ggplot</code> interacts with a single vector. I'm scratching my head, googling for that error gives a single <a href="http://groups.google.com/group/ggplot2/browse_thread/thread/0489a702f3afc83b" rel="noreferrer">result</a>. </p>