I'm trying to create a line plot like this one (made on Powerpoint):
showing the dependency of weight on age (weight~age), for 3 subgroups (so each group has its own line). I also want the chart to show:
- sample size for each point, meaning, the number of individuals for each subgroup at each age.
- significance differences between the subgroups at each age. (TukeyHSD results)
one more important thing: I'm gonna have to repeat those graphs for several parameters (like length~age, and width~age), and also might have to do them several times, so I would really like to avoid manual inserting solutions, like geom_text
if possible..
I've tried several options but keep getting "stuck" at some point. for example:
I have tried this code:
plot_morphologic <- ggplot(data = weight_table,
mapping = aes(x = as.numeric(age),
y = weight, color=POPULATION))+
geom_line(se=TRUE)
but that creates one line for the 3 populations...
I've also tried this:
plot_morphologic <- ggline(data=weight_table, x = "age", y = "weight", add = "mean_sd",
color = "POPULATION")+
stat_compare_means(aes(group = POPULATION), method = "anova", label = "p.signif",
label.y = c(40),na.rm=F)+
stat_n_text(group="POPULATION")
but couldn't split the sample size to each subgroup and couldn't add the significance of the differences between the subgroups.
an example of my data:
weight_table1
# A tibble: 246 × 4
ID POPULATION age weight
<chr> <chr> <chr> <dbl>
1 Shere Khan A 0 13.4
2 Shere Khan A 1 14.2
3 Shere Khan A 2 17.4
4 Serafina B 0 5.19
5 Serafina B 1 15.3
6 Serafina B 2 NA
7 Kaa A 0 7.68
8 Kaa A 1 6.92
9 Kaa A 2 19.4
10 Shenzi C 0 6.96
tnx!!