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 stat_compare_means()
function but failed to use it vertically between lines in my chart.
my current code:
library(tidyverse)
#pivot data into long format
df <- data.frame(
stringsAsFactors = FALSE,
ID = c(1L, 2L, 3L, 4L, 5L),
POPULATION = c("A", "A", "B", "B", "C"),
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)
) %>%
pivot_longer(cols = weight.at.age.1:weight.at.age.3,
names_to = 'age',
values_to = 'weight') %>%
mutate(age = str_remove(age, 'weight.at.age.'))
#plot data
ggline(data = df,
mapping = aes(x = age,
y = weight, add = "mean_se", color=POPULATION))+
stat_compare_means(aes(group = POPULATION), method = "anova", label = "p.signif",
label.y = c(56))
Tnx!