我想显示一个由创建的图,geom_smooth()但是对我来说,能够描述如何创建该图很重要。
我可以从文档中看到,当n> = 1000时,使用gam作为平滑函数,但是我看不到使用了多少个结或使用哪个函数生成了平滑。
例:
library(ggplot2)
set.seed(12345)
n <- 3000
x1 <- seq(0, 4*pi,, n)
x2 <- runif(n)
x3 <- rnorm(n)
lp <- 2*sin(2* x1)+3*x2 + 3*x3
p <- 1/(1+exp(-lp))
y <- ifelse(p > 0.5, 1, 0)
df <- data.frame(x1, x2, x3, y)
# default plot
ggplot(df, aes(x = x1, y = y)) +
geom_smooth()
# specify method='gam'
# linear
ggplot(df, aes(x = x1, y = y)) +
geom_smooth(method = 'gam')
# specify gam and splines
# Shows …Run Code Online (Sandbox Code Playgroud)