geom_bar percentage for each group in x
<p>When I try to calculate the percentage of observations in <code>geom_bar</code> with <code>y = (..count..)/sum(..count..)*100</code>, it does not provide the percentage by each group in <code>x</code>. Here's an example:  </p>

<pre><code>ggplot(data = mtcars)+
  geom_bar(aes(x = factor(cyl), 
               y = (..count..)/sum(..count..)*100,
               fill = factor(gear)),
           position = "dodge")  
</code></pre>

<p>Here, the sum of the percentages of all bars for a given factor(cyl) is not 100%; instead you reach 100% when you add the percentages of all bars in all groups. For example, for the <code>factor(cyl)==4</code>, the proportions are 1/11, 8/11 and 2/11:  9% +73% + 18% = 100%, but the code above shows the percentages: 3.12%, 25% and 6.25% (the sum is not equal to 100% by group). How can I make it show percentages by groups?</p>