title: R: how to add significance differences between sub groups on a line plot
body: <p>I have a line plot for 3 different groups and I would like to present on the chart, in addition to the significant differences, the significance of the differences between subgroups. For example, add the significance of the difference between each of the 3 populations' weights at age 1. I saw the <code>stat_compare_means()</code> function but failed to use it vertically between lines in my chart.
  my current code:</p>
  <pre><code>library(tidyverse)
  #pivot data into long format
  
  df &lt;- data.frame(
    stringsAsFactors = FALSE,
                  ID = c(1L, 2L, 3L, 4L, 5L),
          POPULATION = c(&quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;B&quot;, &quot;C&quot;),
     weight.at.age.1 = c(13.37, 5.19, 7.68, 6.96, 10.35),
     weight.at.age.2 = c(14.15, 15.34, 6.92, 15.12, 8.86),
     weight.at.age.3 = c(17.36, NA, 19.42, 36.39, 26.33)
  ) %&gt;% 
    pivot_longer(cols = weight.at.age.1:weight.at.age.3, 
                 names_to = 'age', 
                 values_to = 'weight') %&gt;% 
    mutate(age = str_remove(age, 'weight.at.age.'))
  
  #plot data
  ggline(data = df, 
         mapping = aes(x = age, 
                       y = weight, add = &quot;mean_se&quot;, color=POPULATION))+
    stat_compare_means(aes(group = POPULATION), method = &quot;anova&quot;, label = &quot;p.signif&quot;, 
                       label.y = c(56))
  </code></pre>
  <p>Tnx!</p>