I'm plotting some data and have the following code:
ggplot(aes(x = x, y = y), data = data) +
geom_point(alpha = 1/15, color = 'blue')+
scale_y_continuous('y')+
scale_x_continuous('x')+
geom_smooth(stat = 'smooth', color = 'Red')
The graph looks like this:
But if I specify 'gam' in the the geom_smooth
function, like:
geom_smooth(stat = 'smooth', color = 'Red', method = 'gam')
I get a different result:
Why is this happening?
In the Documentation, you can see that:
Note that when method 'auto' uses gam, it also changes the formula. The default formula is
So in the first scenario, it uses method gam, with the modified function function y ~ s(x, bs = "cs"). The second time, you only specify that method 'gam' should be used, but you don't overwrite the formula, so y ~x is still used. You could do this:
To get the same result. Hope this helps!