[英]How to use multiple variables with geom_smooth in ggplot2 in r
Just like the title, I want to use multiple independent variables in my model.就像标题一样,我想在我的 model 中使用多个自变量。
There is an easy example:有一个简单的例子:
If I want to see the relationship between mpg
and disp
, I could use this:如果我想查看mpg
和disp
之间的关系,我可以使用这个:
mtcars %>% ggplot(aes(y = mpg, x = disp)) +
geom_point() +
geom_smooth(formula = y ~ x)
Then I want to see the relationship between mpg
and disp
adjusted hp
, I write the below code occurring an error:然后我想看看mpg
和disp
之间的关系调整了hp
,我写了下面的代码发生错误:
mtcars %>% ggplot(aes(y = mpg, x = disp)) +
geom_point() +
geom_smooth(formula = y ~ x + hp)
# Computation failed in `stat_smooth()`:
# object 'hp' not found
Maybe I didn't mapping hp
in ggplot(aes())
, and I tried this but the same error occurring:也许我没有在ggplot(aes())
中映射hp
,我尝试了这个但是发生了同样的错误:
mtcars %>% ggplot(aes(y = mpg, x = disp, z = hp)) +
geom_point() +
geom_smooth(formula = y ~ x + z)
Any help will be highly appreciated!任何帮助将不胜感激!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.