This is probably a very basic question but I haven't found an answer yet. Is there an equivalent to the span
argument in the geom_smooth
function when method = "gam"
? I am not familiar with GAM's in general so I would appreciate any input on that. I want to add a more flexible (wigglier) smoother to data with n > 1'000 and method = "loess"
takes a lot of time to calculate.
Equivalent of span using geom_smooth() with "gam"
mgcv::gam
by default optimizes the smoothness using penalized regression. You can switch that off and specify the smoothness manually with the k
parameter:
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
geom_smooth(method = "gam",
formula = y ~ s(x, bs = "cs", fx = TRUE, k = 20))
You should probably study the documentation of package mgcv.
Thank you so much, that was exactly what I was looking for. I already guessed that number of knots were involved in this but I couldn't figure out how to get this done. –
Wb
© 2022 - 2024 — McMap. All rights reserved.