[英]ggplot2 in R: use `geom_ribbon` for shading under two different `geom_smooth` lines
[英]How to use multiple variables with geom_smooth in ggplot2 in r
就像標題一樣,我想在我的 model 中使用多個自變量。
有一個簡單的例子:
如果我想查看mpg
和disp
之間的關系,我可以使用這個:
mtcars %>% ggplot(aes(y = mpg, x = disp)) +
geom_point() +
geom_smooth(formula = y ~ x)
然后我想看看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
也許我沒有在ggplot(aes())
中映射hp
,我嘗試了這個但是發生了同樣的錯誤:
mtcars %>% ggplot(aes(y = mpg, x = disp, z = hp)) +
geom_point() +
geom_smooth(formula = y ~ x + z)
任何幫助將不勝感激!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.