title: Label selected percentage values inside stacked bar plot (ggplot2)
body: <p>I want to put labels of the percentages on my stacked bar plot. However, I only want to label the largest 3 percentages for each bar. I went through a lot of helpful posts on SO (for example: <a href="https://stackoverflow.com/questions/12386005/r-stacked-percentage-bar-plot-with-percentage-of-binary-factor-and-labels-with">1</a>, <a href="https://stackoverflow.com/questions/14941940/r-stacked-bar-graph-plotting-geom-text">2</a>, <a href="https://stackoverflow.com/questions/14933242/how-to-label-percentage-values-inside-stacked-bar-plot-using-r-base">3</a>), and here is what I've accomplished so far:</p>
  
  <pre><code>library(ggplot2)
  groups&lt;-factor(rep(c("1","2","3","4","5","6","Missing"),4))
  site&lt;-c(rep("Site1",7),rep("Site2",7),rep("Site3",7),rep("Site4",7))
  counts&lt;-c(7554,6982, 6296,16152,6416,2301,0,
            20704,10385,22041,27596,4648, 1325,0,
            17200, 11950,11836,12303, 2817,911,1,
            2580,2620,2828,2839,507,152,2)
  tapply(counts,site,sum)
  tot&lt;-c(rep(45701,7),rep(86699,7), rep(57018,7), rep(11528,7))
  prop&lt;-sprintf("%.1f%%", counts/tot*100)
  
  data&lt;-data.frame(groups,site,counts,prop)
  
  ggplot(data, aes(x=site, y=counts,fill=groups)) + geom_bar()+
    stat_bin(geom = "text",aes(y=counts,label = prop),vjust = 1) +
    scale_y_continuous(labels = percent)
  </code></pre>
  
  <p>I wanted to insert my output image here but don't seem to have enough reputation...But the code above should be able to produce the plot.</p>
  
  <p>So how can I only label the largest 3 percentages on each bar? Also, for the legend, is it possible for me to change the order of the categories? For example put "Missing" at the first. This is not a big issue here but for my real data set, the order of the categories in the legend really bothers me. </p>
  
  <p>I'm new on this site, so if there's anything that's not clear about my question, please let me know and I will fix it. I appreciate any answer/comments! Thank you!</p>