The example code is the following (it may have no sense statistically, but the problem is the object not found
). While next works:
mtcars %>% ggplot(aes(x = vs, y = mpg)) + geom_smooth(method="lm")
Next does not:
> 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
Why this error? What can I do to solve it?
I also tried
> 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
and other variants with ""
, with more info inside lm
, etc., but without success.
Thank you very much!