【发布时间】:2021-02-24 08:18:09
【问题描述】:
第一次在这里发帖。
我似乎找不到一种简单的方法来将指数趋势线添加到我的各种散点图中。我有 8 种树种,它们的高度(以米为单位)和胸高的直径(简称 DBH,以厘米为单位)的关系不同。现在我已经设法为每种树种绘制了不同的散点图,但我似乎找不到添加指数趋势线的方法。 Scatter Plot of DBH - Height Relationship per Tree type
我使用的代码如下:
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)")
当我添加geom_smooth 函数时,我似乎无法添加指数趋势线,因为我知道这些类型的关系最适合。我尝试使用的代码是:
geom_smooth(method = "nls", formula = y ~ a * exp(b * x), aes(color = "Exponential"),
se = FALSE, start = c(a = 1, b= 1))`
如果还有可能添加 R2 值,那也将受到欢迎。 我将不胜感激!
【问题讨论】:
-
在您尝试
geom_smooth函数后得到了什么输出或错误? -
大约有 17 个警告,但它们的状态都相同:
Computation failed instat_smooth(): number of iterations exceeded maximum of 50 14: In (function (formula, data = parent.frame(), start, control = nls.control(), ... : No starting values specified for some parameters. Initializing ‘a’, ‘b’ to '1.'. Consider specifying 'start' or using a selfStart model'
标签: r ggplot2 exponential