'Logged linear regression, Add a trendline to a scatter plot
I have a linear regression model that has root mass as y and aboveground tree mass as x.
model2<-lm(log(root_total)~log(abv_total),data=Li2003hardwood)
I would like to add a trendline for this model using ggplot but I don't know how to specify the model I used. I know formula=y~log(x) is not correct its just there as a place holder.
Also I am just trying to recreate a plot from a old publication (Belowground biomass dynamics in the Carbon Budget Model of the Canadian Forest Sector) with the original data. Trying to understand how to add the trendline that follows the logged data but keep the axis unlogged as they did in the publication.
ggplot(data=Li2003hardwood,aes(x=abv_total,y=root_total))+
geom_point()+
geom_smooth(method="lm",formula=y~log(x),se=FALSE,color="black")
Solution 1:[1]
I was able to figure out how to add the trend line.
plot(root_total~abv_total,data=Li2003hardwood)
curve(exp(predict(model2,
newdata = data.frame(abv_total = x))), col = "black", add = TRUE)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ben Bolker |
