For separate regression lines on the same plot/facet you can do this:
ggplot(oceanregression, aes(x=log_phosphorus, y=chl.a_mg.m3, color=location))+
geom_point(col="black", size=2.5)+
xlab("log phosphorus nmol/L")+
ylab("Concentration of Chl in mg/m3")+
theme_classic()+
geom_smooth(method=lm, formula=y~x)
If you want to have split into facets, you can do this:
ggplot(oceanregression, aes(x=log_phosphorus, y=chl.a_mg.m3, color=location))+
geom_point(col="black", size=2.5)+
xlab("log phosphorus nmol/L")+
ylab("Concentration of Chl in mg/m3")+
theme_classic()+
facet_wrap(~location)+
geom_smooth(method=lm, formula=y~x)
Input Data:
set.seed(123)
oceanregression = data.table(
location=c(rep("A", 10), rep("B", 10)),
log_phosphorus = rep(1:10,2),
chl.a_mg.m3 = rnorm(20)
)
Read more here: Source link