Setting method as default method in geom_smooth gives different result

后端 未结 1 1240
清歌不尽
清歌不尽 2021-01-18 09:37

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_contin         


        
相关标签:
1条回答
  • 2021-01-18 10:44

    In the Documentation, you can see that:

    smoothing method (function) to use, eg. "lm", "glm", "gam", "loess", "rlm".

    For method = "auto" the smoothing method is chosen based on the size of the largest group (across all panels). loess is used for less than 1,000 observations; otherwise gam is used with formula = y ~ s(x, bs = "cs"). Somewhat anecdotally, loess gives a better appearance, but is O(n^2) in memory, so does not work for larger datasets.

    Note that when method 'auto' uses gam, it also changes the formula. The default formula is

    formula = y ~ x

    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:

    geom_smooth(stat = 'smooth', color = 'Red', method = 'gam', formula = y ~ s(x, bs = "cs"))
    

    To get the same result. Hope this helps!

    0 讨论(0)
提交回复
热议问题