title: R, ggplot stacked bar-chart with position = "fill" and labels
body: <p><br>
  I'm working with <code>ggplot2</code>, stacked barplot to 100% with relative values, using the <code>position = "fill"</code> option in <code>geom_bar()</code>.
  <br>
  Here my code:</p>
  
  <pre><code>test &lt;- data.frame (x = c('a','a','a','b','b','b','b')
          ,k = c('k','j','j','j','j','k','k')
          ,y = c(1,3,4,2,5,9,7))
  
  plot &lt;- ggplot(test, aes(x =x, y = y, fill = k)) 
  plot &lt;- plot + geom_bar(position = "fill",stat = "identity") 
  plot &lt;- plot +  scale_fill_manual(values = c("#99ccff", "#ff6666"))
  plot &lt;- plot  + geom_hline(yintercept = 0.50)+ggtitle("test")
  plot
  </code></pre>
  
  <p>Here the result:</p>
  
  <p><a href="https://i.stack.imgur.com/97b8r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/97b8r.png" alt="enter image description here"></a>  </p>
  
  <p>However, I need to add the labels on the various bars, also on the "sub bars". To do this, I worked with the geom_text():</p>
  
  <pre><code>plot  + geom_text(aes(label=y, size=4))
  </code></pre>
  
  <p>But the result is not good. I tried without luck the <code>hjust</code> and <code>vjust</code> parameters, and also using something like:</p>
  
  <pre><code>plot  + geom_text(aes(label=y/sum(y), size=4))
  </code></pre>
  
  <p>But I did not reach the result needed (I'm not adding all the tests to not overload the question with useless images, if needed, please ask!). <br>
  Any idea about to have some nice centered labels?</p>