【发布时间】:2019-10-10 10:17:43
【问题描述】:
示例代码如下(可能统计上没有意义,但问题是object not found)。接下来的工作:
mtcars %>% ggplot(aes(x = vs, y = mpg)) + geom_smooth(method="lm")
下一个没有:
> mtcars %>% ggplot(aes(x = vs, y = mpg)) + geom_smooth(method=lm(weights = cyl))
Error in stats::model.frame(weights = cyl, drop.unused.levels = TRUE) :
object 'cyl' not found
为什么会出现这个错误?我能做些什么来解决它?
我也试过
> mtcars %>% ggplot(aes(x = vs, y = mpg)) + geom_smooth(method=lm(weights = "cyl"))
Error in terms.formula(formula, data = data) :
argument is not a valid model
以及其他带有"" 的变体,在lm 中包含更多信息等,但没有成功。
非常感谢!
【问题讨论】:
-
试试这个...
geom_smooth(aes(weight = cyl), method = "lm") -
正如@AndrewGustar 所指出的,specify weights in the
weightaesthetic -
我已经看过stackoverflow.com/questions/42507098/…,但我觉得它不起作用。谢谢!
标签: r ggplot2 lm smoothing weighted