title: ggplot2 put text between two violin plots in facet_grid with geom_text
body: <p>I have seen a number of questions related to what I'm asking, but not addressing my issue directly. I am making a panel of overlaid violin and boxplots in a facet_grid with ggplot. The data is split by a control and experimental variable and in each facet plot I simply want to put an asterisks or &quot;ns&quot; above and between the control and experimental group.</p>
  <p>Here is some example data:</p>
  <pre><code>library(ggplot2)
  type&lt;- c(&quot;a&quot;, &quot;a&quot;, &quot;a&quot;, &quot;a&quot;,&quot;a&quot;, &quot;a&quot;, &quot;a&quot;, &quot;a&quot;, &quot;b&quot;, &quot;b&quot;, &quot;b&quot;, &quot;b&quot;, &quot;b&quot;, &quot;b&quot;)
  value&lt;- as.numeric(c(&quot;9&quot;, &quot;9.5&quot;, &quot;9.1&quot;, &quot;9.8&quot;, &quot;8.8&quot;, &quot;8.7&quot;, &quot;8.9&quot;, &quot;9&quot;, &quot;9.5&quot;, &quot;9.1&quot;, &quot;9.8&quot;, &quot;8.8&quot;, &quot;8.7&quot;, &quot;8.9&quot;))
  group&lt;- c(&quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;2&quot;, &quot;2&quot;, &quot;2&quot;, &quot;2&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;2&quot;, &quot;2&quot;, &quot;2&quot;)
  
  data&lt;-data.frame(type, value, group)
  </code></pre>
  <p>This code will generate a plot:</p>
  <pre><code>plot1&lt;- ggplot(data, aes(x=group, y= value))+
    facet_grid(~type)+
    geom_violin(aes(color=group), size=0.5)+
    geom_boxplot(width=0.3, size=0.5, color=&quot;black&quot;)+
    ylim(5,11)+
    scale_colour_manual(
      values = c(&quot;1&quot;=&quot;black&quot;, &quot;2&quot;=&quot;red&quot;))+
    theme(
      panel.background = element_rect(fill=&quot;white&quot;), 
      axis.line = element_line(size=1, colour = &quot;black&quot;)
    ) 
  </code></pre>
  <p>I want an asterisks between groups 1 and 2 in each plot. Here is some dummy data for the text annotation:</p>
  <pre><code>text&lt;- c(&quot;*&quot;, &quot;ns&quot;)
  type&lt;- c(&quot;a&quot;, &quot;b&quot;)
  value2&lt;- as.numeric(&quot;10.5&quot;, &quot;10.5&quot;)
  
  statsDf&lt;- data.frame(text, type, value2)
  </code></pre>
  <p>And here is the geom_text argument I use to add the text annotations:</p>
  <pre><code>  geom_text(data=statsDf,
              size=10,
              mapping=aes(x=Inf, y=value2,
                          label = text))
  </code></pre>
  <p>When I add this to the plot, I get the following:</p>
  <p><a href="https://i.stack.imgur.com/zFdDw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zFdDw.png" alt="enter image description here" /></a></p>
  <p>Id like the text centered in each plot, but I don't know how to define the x value to do so.</p>
  <p>Anyone mind giving me a hand?</p>