title: How to add percentages to bar chart facets in ggplot2 in R?
body: <p>I wanted make a plot using ggplot2 so that there are bar charts displaying the degrees (bars) people in each kind of urban/rural environment (facet) hold. I achieved that. </p>
  
  <p>Now I want to add ratios of the people with each kind of qualification <em>for each facet</em>. What I got using the code below is percentages <em>for the whole population</em>.</p>
  
  <p>How can I change the code so that the percentages will be counted inside each facet? </p>
  
  <p>Here is a sample with 1,000 rows from the data set I used: <a href="http://s000.tinyupload.com/?file_id=02792393224272274158" rel="nofollow noreferrer">link</a>.</p>
  
  <pre><code>library(ggplot2)
  library(scales)
  
  # plot urban/rural by degree in facets
   myplot &lt;- ggplot(data = si
                       ,aes(DEGREE)
      ) 
      myplot &lt;- myplot + geom_bar()
      myplot &lt;- myplot + labs(title = "Degree by Urban/Rural", y = "Percent", x = "DEGREE")
      myplot &lt;- myplot + geom_text(aes(y = ((..count..)/sum(..count..)), label = scales::percent((..count..)/sum(..count..))), stat = "count", vjust = -0.25)
      myplot &lt;- myplot + facet_wrap(~URBRURAL)
      myplot &lt;- myplot + theme(axis.text.x = element_text(angle = 20, hjust = 1))
      myplot
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/V6T6k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V6T6k.png" alt="enter image description here"></a></p>