title: Nudge ggplot text based on value
body: <p>How would I nudge text based on value:</p>
  
  <p>E.g.,</p>
  
  <pre><code>library(ggplot2)
  theme_set(theme_bw())  
  
  # Data Prep
  data("mtcars")  # load data
  mtcars$`car name` &lt;- rownames(mtcars)  # create new column for car names
  mtcars$mpg_z &lt;- round((mtcars$mpg - mean(mtcars$mpg))/sd(mtcars$mpg), 2)  # compute normalized mpg
  mtcars$mpg_type &lt;- ifelse(mtcars$mpg_z &lt; 0, "below", "above")  # above / below avg flag
  mtcars &lt;- mtcars[order(mtcars$mpg_z), ]  # sort
  mtcars$`car name` &lt;- factor(mtcars$`car name`, levels = mtcars$`car name`)  # convert to factor to retain sorted order in plot.
  
  # Diverging Barcharts
  ggplot(mtcars, aes(x=`car name`, y=mpg_z, label=mpg_z)) + 
    geom_bar(stat='identity', aes(fill=mpg_type), width=.5)  +
    scale_fill_manual(name="Mileage", 
                      labels = c("Above Average", "Below Average"), 
                      values = c("above"="#00ba38", "below"="#f8766d")) + 
    geom_text(size=2, nudge_y = 0.1) +
    labs(subtitle="Normalised mileage from 'mtcars'", 
         title= "Diverging Bars") + 
    coord_flip()
  </code></pre>
  
  <p>Currently, text shows on top of negative bars: <a href="https://i.stack.imgur.com/vQMON.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vQMON.png" alt="enter image description here"></a></p>
  
  <p>I'd like to nudge it to the left only for these bars, to the right for positive bars.</p>
  
  <p>Example <a href="http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html" rel="noreferrer">source</a></p>