I'm plotting some log-scaled data with an overlain linear fit line, like so:
d <- data.frame(x=1:10, y=10^(1:10 + rnorm(10)))
ggplot(d, aes(x=x, y=y)) + geom_point() +
geom_smooth(method="lm", se=FALSE) +
scale_y_log10()
It looks like the linear regression line is being calculated on the transformed data, or else it would go directly through the last point. Is that true?
I seem to remember that this is addressed in the ggplot2
text, but I can't find it now.
When ggplot
renders a plot, it does so in the following order:
scale_
functions, typically)lm
fit, in this case -- this is where stat_
functions come in, which are typically called through geom_
functions)So, scaling happens before the model is fit, and hence yes, the fit is being calculated on the transformed data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With