title: How to label the outliers of boxplot with ggplot2?
body: <p>My data is as follows:</p>
  
  <pre><code>genes   fc   type
  349028  -1.2 pro
  2454    1.1  pro
  24908   0.4  pro
  4730    0.8  pro
  94988   0.9  pro
  9865    6    pro
  8935    3.4  phos
  39280   1.2  phos
  8034    -0.3 phos
  3953    1.1  phos
  4732    2.1  phos
  </code></pre>
  
  <p>I want to label the outliers of boxplot with ggplot2 and plot all the points with "jitter", but the outlier appear twice. My code is as follows:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>pathdata=read.table(file="data.txt",header=TRUE,quote="",sep="\t")
  library(ggplot2)
  library(dplyr)
  is_outlier &lt;- function(x) {
    return(x &lt; quantile(x, 0.25) - 1.5 * IQR(x) | x &gt; quantile(x, 0.75) + 1.5 * IQR(x))
  }
  pathdata %&gt;%
   group_by(type) %&gt;%
   mutate(outlier=ifelse(is_outlier(fc),genes,as.numeric(NA))) %&gt;%
   ggplot(., aes(x = factor(type), y = fc)) +
      geom_boxplot() + 
   geom_point(size=1.5, aes(x=jitter(as.numeric(type)), color = fc))+
   scale_colour_gradient(low="blue",high="red") +
      geom_text(aes(label = outlier), na.rm = TRUE, hjust = -0.3)</code></pre>
  </div>
  </div>
  </p>
  
  <p>I got the figure:<a href="https://i.stack.imgur.com/R3pxP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R3pxP.png" alt="enter image description here"></a></p>
  
  <p>If I add <code>outlier.size=-1</code> in the <code>geom_boxplot()</code>, I will get:
  <a href="https://i.stack.imgur.com/Hb8im.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hb8im.png" alt="enter image description here"></a></p>
  
  <p>But the label is not close to the point which representing. Can someone tell me how to adjust my code? Thanks! </p>