first time posting a question in here.
I can't seem to find an easy way to add an exponential trendline to my various scatterplots. I have 8 tree species with different relationships of their height (in meters) and its diameter at breast height (DBH for short in cm). For now I have managed to do the different scatter plots for each tree species, but I can't seem to find a way to add an exponential trendline. Scatter Plot of DBH - Height Relationship per Tree type
The code I used is as follows:
ggplot(data, aes(Height__m_,DBH__cm_)) +
geom_point(aes(color = Species)) +
facet_wrap(~Species, ncol = 4, nrow = 2) +
labs(title = "DBH - Height Relationship", y = "Height (m)", x = "DBH (cm)")
When I add the geom_smooth
function, I can't seem to add an exponential trendline since I know these types of relationships to be the best fit. The code I've tried using is:
geom_smooth(method = "nls", formula = y ~ a * exp(b * x), aes(color = "Exponential"),
se = FALSE, start = c(a = 1, b= 1))`
If there's also a possibility of adding the R2 value, that would also be welcomed. I would appreciate the help!