'Fitting LOESS function in ggplot

How can I modify the method= argument in ggplot so to customize my loess function?

Right now this is my code without implementing a function:

ggplot(data, aes(x = X, y = Y)) +
  geom_point() +
  geom_smooth(method = "loess", fill='darkred', level=0.90)

And this is the function I would like to implement under the method= argument:

loess(Y ~ X, data=data, span=0.08, degree =1, family = 'gaussian')


Solution 1:[1]

You can pass arguments to loess() via the method.args argument of geom_smooth():

Edit following comments:

ggplot(data, aes(x = X, y = Y)) +
  geom_point() +
  geom_smooth(method = "loess", span=0.08, fill='darkred', level=0.90, method.args=list(degree =1, family = 'gaussian'))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1