title: In ggplot2 how to show emmeans contrast significant p values in plot edited
body: <p>I have been copying my boxplot graphs to word and manually putting in the significant p-values. When I use the recommended code  <strong>stat_compare_means(comparisons = my_comparisons, label.y = c(85, 90, 95)</strong>  I end up with numbers that are not accurate. What I am looking for is for a bracket with significant p=values from the last line of code  <strong>emmeans(lmer2, pairwise ~ Year | transect)</strong> from the results of emmeans contrasts. I have tried using the word contrasts instead of comparison</p>
  <p>Here is the source code I ran</p>
  <p><a href="https://rpubs.com/mberry1/713185" rel="nofollow noreferrer">https://rpubs.com/mberry1/713185</a></p>
  <p>example code</p>
  <h1></h1>
  <pre><code>plots     transect  Year Total
  &lt;chr&gt;        &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
  1 D11_NORTH        1     1   46 
  2 D11_SOUTH        1     1   56.
  3 R27_NORTH        1     1   34 
  4 R27_SOUTH        1     1   38 
  5 R28_NORTH        1     1   50 
  6 R28_SOUTH        1     1   34 
  7 D13_NORTH        2     1   60 
  8 D13_SOUTH        2     1   10 
  
  glm_test$year &lt;- factor(glm_test$year,
                      levels = c(1, 2, 3),
                      labels = c(&quot;2018&quot;, &quot;2019&quot;, &quot;2020&quot;))
  
  
  glm_test$transect &lt;- factor(glm_test$transect,
                          levels = c(1, 2,3),
                          labels = c(&quot;Lower Meadow&quot;, &quot;Middle Meadow&quot;, &quot;Upper 
  Meadow&quot;))
  summary(glm_test)
  </code></pre>
  <p>#run the linear model with cover as dependent variable, year as
  #independent var. for the plot by stating + (1| plot), This makes it a #repeated measures</p>
  <pre><code>lmer2 &lt;- lmer(cover ~ as.factor(year) * as.factor(transect) + (1|plot), 
            data = glm_test)
  anova(lmer2)
  </code></pre>
  <p>#post Hoc comparisons</p>
  <pre><code>emmeans(lmer2, list(pairwise ~ year), adjust = &quot;tukey&quot;)  
  </code></pre>
  <p>#If there was an interaction your code would be this</p>
  <pre><code>emmeans(lmer2, pairwise ~ year | transect)
                                
  </code></pre>
  <p>Results of Contrasts for transect = Upper Meadow:</p>
  <p>|contrast    |  estimate|  SE df| t.ratio| p.value|
  | ---------- | -------- | ----- | ------ | ------ |
  |2018 - 2019 |  27.500  |7.15 38|  3.848 | 0.0013 |
  |2018 - 2020 |  20.000  |7.15 38|  2.798 | 0.0214 |
  |2019 - 2020 |  -7.500  |7.15 38| -1.049 | 0.5509 |
  Degrees-of-freedom method: kenward-roger
  P value adjustment: tukey method for comparing a family of 3 estimates</p>
  <p>#Visulize data</p>
  <pre><code>ggboxplot(glm_test, x = &quot;year&quot;, y = &quot;cover&quot;, title = &quot;Total % Cover of 
  Upland 
  Species Across All Years&quot;,
        ylab = &quot; % Cover UPL Species&quot;,
        color = &quot;transect&quot;, ggtheme = theme_gray(base_size = 14))+
  stat_compare_means(comparisons = my_comparisons, label.y = c(85, 90, 95))+
  stat_compare_means(label.y = 110)
  </code></pre>
  <p><img src="https://i.stack.imgur.com/7LHsc.png" alt="enter image description here" /></p>
  <p>The above boxplot does not make sense to me, I am looking for the significant p-values in the emmenas contrast above. The below boxplot is one I placed p-values in by hand in word</p>
  <p><img src="https://i.stack.imgur.com/MeZtJ.png" alt="enter image description here" /></p>