This is the loess smoothing curve in base r
dat <- data.frame(RT = c(151, 160, 168, 169, 172, 175, 189, 279),
IQ = c(123, 121, 115, 110, 105, 103, 100, 120))
with(dat, scatter.smooth(IQ, RT, span = 0.8))
And this is the loess curve produced with ggplot:
ggplot(dat, aes(x = IQ, y = RT)) +
geom_point() +
geom_smooth(method = stats::loess, se = F, span = 0.8)
Why are they different?
It's because scatter.smooth()
does not use the default loess()
arguments, whereas geom_smooth()
does. If you provide the method arguments that are default in scatter.smooth()
to the ggplot2 method, they produce very similar results.
dat <- data.frame(RT = c(151, 160, 168, 169, 172, 175, 189, 279),
IQ = c(123, 121, 115, 110, 105, 103, 100, 120))
with(dat, scatter.smooth(IQ, RT, span = 0.8))
library(ggplot2)
ggplot(dat, aes(x = IQ, y = RT)) +
geom_point() +
geom_smooth(formula = y ~ x, method = "loess", se = F, span = 0.8,
method.args = list(degree = 1, family = "symmetric"))
Created on 2021-02-03 by the reprex package (v1.0.0)