stats::model.frame…:在geom_smooth内指定权重时未找到对象

stats::model.frame…:在geom_smooth内指定权重时未找到对象,r,ggplot2,lm,smoothing,weighted,R,Ggplot2,Lm,Smoothing,Weighted,示例代码如下(在统计上可能没有意义,但问题是未找到对象)。下一步工作时: 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

示例代码如下(在统计上可能没有意义,但问题是未找到
对象
)。下一步工作时:

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
中包含更多信息,等等,但没有成功

多谢各位

mtcars %>% ggplot(aes(x = vs, y = mpg)) +  
   stat_smooth(method="lm", aes(weight= cyl))

这将生成一个图表,但我不确定它是否是您想要的<代码>权重此处可能与要使用的
权重
相同

试试这个
geom_smooth(aes(weight=cyl),method=“lm”)
正如@AndrewGustar指出的,这与我已经看到的您的问题类似,我觉得它不起作用。非常感谢。