I'm trying to add multiple trendlines to a scatter plot in ggplot by age groups. I have 4 Age_range's 20_under, 21_24, 25_29, and 30_up so I'm looking to have 4 trendlines for each of these age groups
library(ggplot2)
library(ggpubr)
ggplot( cars, aes( x = horsepower, y = miles, color = Age_range))+
geom_point()+
geom_smooth(method=lm)+
stat_cor(method = "pearson", label.x = 77, label.y = -3000)
I've hit a total roadblock. I tried working off a couple of similar questions on Stack Overflow but nothing seems to work.

You need to set the
aes(color = ...)insidestat_coras well or setinherit.aes = TRUE. Also, don't provide bothlabel.xandlabel.yinstat_coras that would cause the labels to print over each other when you have multiple groups.Created on 2024-01-22 with reprex v2.0.2