【发布时间】:2026-01-28 12:00:01
【问题描述】:
我正在尝试在 ggplot 中的同一数字上绘制回归估计中的隐含函数。在下面的示例中,我创建了一个简单的线性函数,其中 c 和 b 是从早期回归中存储的系数估计值。然后我试图按组在 [0,50] 范围内绘制函数(最好也使用选项:color = groups)。
library(ggplot2)
groups = c("a", "b", "c")
c = c(5, 4, 3)
b = c(-0.01, -0.002, -0.001)
x = c(0, 0, 0)
df <- data.frame(cbind(c, b, x))
grad_fun <- function(x) {
c + b*x
}
ggplot(data = df, aes(x = x, group = groups)) +
stat_function(fun = grad_fun) +
xlim(0, 50)
我的身材是这样的,但我似乎无法找出原因。欢迎任何有关如何解决此问题的建议。 Image: Outcome of above code
【问题讨论】: