title: Centre and offset labels in ggplot2
body: <p>I have made a plot, but i have two issues that i need help with.</p>
  
  <p><strong>Question 1)</strong></p>
  
  <p>How do i centre the labels in each section of the bars?
  While searching for a solution, i have tried to change the line:</p>
  
  <pre class="lang-r prettyprint-override"><code>  geom_text(aes(label= paste(round(pct),"%")), color = "white", size=2.6, position="fill", stat="identity") 
  </code></pre>
  
  <p>to</p>
  
  <pre><code>  geom_text(aes(label= paste(round(pct),"%")), color = "white", size=2.6, position=position_stack(vjust = 0.5))
  </code></pre>
  
  <p>This puts the labels in the correct place, but now the colored bars are not printet.</p>
  
  <p><strong>Question 2)</strong></p>
  
  <p>Where the plot will be used, it is going to be rather narrow like in this picture: <a href="https://i.stack.imgur.com/TCk9Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TCk9Z.png" alt="this picture"></a>.</p>
  
  <p>Is there a way to automatically deal with overlapping labels? Another helpfull solution could be to offset every other label, so that first label is above the middle of the bar, and the second label is below the middle (I hope this makes sense). Other solutions are also welcome.</p>
  
  <p>Code to reproduce my plot:</p>
  
  <pre><code>library(ggplot2)
  
  exdata &lt;- structure(list(Var1 = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 
                                              4L), .Label = c("Meget ofte", "Ofte", "Nogle gange", "Aldrig eller næsten aldrig"
                                              ), class = "factor"), Freq = c(4L, 16L, 50L, 38L, 6L, 5L, 55L, 
                                                                             43L), spm = c("Question 1: aaaaaabbbbbbbbbcccccc", "Question 1: aaaaaabbbbbbbbbcccccc", 
                                                                                           "Question 1: aaaaaabbbbbbbbbcccccc", "Question 1: aaaaaabbbbbbbbbcccccc", 
                                                                                           "Question 2: aaaaaabbbbbbbbbcccccc", "Question 2: aaaaaabbbbbbbbbcccccc", 
                                                                                           "Question 2: aaaaaabbbbbbbbbcccccc", "Question 2: aaaaaabbbbbbbbbcccccc"
                                                                             ), pct = c(3.7037037037037, 14.8148148148148, 46.2962962962963, 
                                                                                        35.1851851851852, 5.5045871559633, 4.58715596330275, 50.4587155963303, 
                                                                                        39.4495412844037)), row.names = 21:28, class = "data.frame")
  
  palette1 &lt;- c("#00ABA4", "#008983", "#006763", "#004543")
  
  plot1 &lt;- ggplot(data=exdata, aes(y=Freq, x=spm, fill= fct_rev(Var1))) +
    geom_bar(position="fill", stat="identity") +
    scale_fill_manual(values=c(palette1)) +
    geom_text(aes(label= paste(round(pct),"%")), color = "white", size=2.6, position="fill", stat="identity") + 
    coord_flip() +
    labs(fill = "Svar") +
    labs(title = "Hvor often do you do these things?") +
    ylab("Percentage") +
    xlab("Question") +
    theme(legend.position="bottom", legend.title=element_text(size=10)) +
    guides(fill =guide_legend(reverse = TRUE,nrow=2,byrow=TRUE)) 
  
  plot1
  
  </code></pre>