【问题标题】:Error in stats::model.frame...: object not found when specifying weights inside geom_smoothstats::model.frame 中的错误...:在 geom_smooth 中指定权重时找不到对象
【发布时间】: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 中包含更多信息等,但没有成功。

非常感谢!

【问题讨论】:

标签: r ggplot2 lm smoothing weighted


【解决方案1】:
mtcars %>% ggplot(aes(x = vs, y = mpg)) +  
   stat_smooth(method="lm", aes(weight= cyl))

这将生成一个图表,但我不确定它是否是您所追求的。 weight 这里可能与您想使用的 weights 没有什么不同。

【讨论】:

    猜你喜欢
    • 2010-10-20
    • 2011-08-03
    • 1970-01-01
    • 2018-08-15
    • 2021-03-24
    • 2014-04-15
    • 2012-11-20
    • 2018-03-16
    • 2016-04-01
    相关资源
    最近更新 更多