How can I plot the residuals of lm() with ggplot?
Fortify is no longer recommended and might be deprecated according to Hadley.
You can use the broom package to do something similar (better):
library(broom)
y <-rnorm(10)
x <-1:10
mod <- lm(y ~ x)
df <- augment(mod)
ggplot(df, aes(x = .fitted, y = .resid)) + geom_point()
Use ggfortify::autoplot()
for the gg
version of the regression diagnostic plots. See this vignette.
Example
fit <- lm(mpg ~ hp, data = mtcars)
library(ggfortify)
autoplot(fit)