title: Ggplot filled barplot with percentage labels
body: <p>I want to make a simple barplot, I have one variable x (A,B,C,D) categorical, another one y (YES, NO) that I am using to fill, and a set of observations, and I want to display a filled barplot, with percentage labels in each column.</p>
  
  <p>Something as simple as like this: </p>
  
  <p><img src="https://i.stack.imgur.com/DNVry.png" alt="Proper Filled Baplot with %"></p>
  
  <p>So far ggplot layer system has been a nightmare to use. And no solutions I was able to find in already asked questions. </p>
  
  <pre><code>x11()
  ggplot(data=KS, aes(x=KS$main_category, fill=KS$state)) +
      geom_bar(position="fill") +
      scale_y_continuous(labels = percent) +
      geom_text(aes(label = ..count.., group = KS$state), 
                stat = "count")
  </code></pre>
  
  <p>This is what I got so far and a part for positioning it displays the count for every category and state, why can't it display proportions?. And <strong>I want to avoid to manipulate the data</strong> and adding stuff to the dataframe.</p>
  
  <p>Thanks a lot.</p>
  
  <p>Edit: the requested data frame</p>
  
  <pre><code>library("ggplot2")
  library("scales")
  
  main_category=c('A','A','B','C','D','A','A','B','C','D','A','A','B','C','D','A','A','B','C','D')
  state=c('Yes', 'No', 'Yes', 'Yes','Yes', 'No', 'Yes', 'Yes','Yes', 'No', 'Yes', 'Yes','Yes', 'No', 'Yes', 'Yes', 'No', 'No', 'No', 'No')
  KS = data.frame(main_category, state)
  </code></pre>
  
  <p>Edit 2:</p>
  
  <p>I was able to find my own solution without manipulating the dataset by using implicit ggplot variables:</p>
  
  <pre><code>geom_text(aes( y=..count../tapply(..count.., ..x.. ,sum)[..x..], label=percent(..count../tapply(..count.., ..x.. ,sum)[..x..]) ),
                stat="count", position=position_fill(0.5), vjust=0.5)
  </code></pre>