举个例子:
ggplot(iris,aes(Sepal.Width,Sepal.Length)) + geom_smooth()
如何获得用于绘制此蓝色曲线的x
和y
?
此案例将由loess
自动计算,我的实际案例由gam
自动计算。
我试过了:
gam
函数并没有任何成功
答案 0 :(得分:1)
据我所知,请尝试这种方法:
library(gam)
library(broom)
mod <- gam(Sepal.Length ~ Sepal.Width, data = iris)
ggplot(iris, aes(Sepal.Width,Sepal.Length)) + geom_point() +
geom_line(data = augment(mod, type.predict = "response"),
aes(y = .fitted), color = "blue")