I would like to have a nice plot about residuals I got from an lm()
model. Currently I use plot(model$residuals)
, but I want to have something nicer. If I try to plot it with ggplot, I get the error message:
ggplot2 doesn't know how to deal with data of class numeric
4 Answers
Fortify is no longer recommended and might be deprecated according to Hadley.
Plot(lm(distspeed,data=cars)) We’re looking at how the spread of standardized residuals changes as the leverage, or sensitivity of the fitted to a change in, increases. Firstly, this can also be used to detect heteroskedasticity and non-linearity.
You can use the broom package to do something similar (better):
Use ggfortify::autoplot()
for the gg
version of the regression diagnostic plots. See this vignette.
ggplot
wants a data.frame. fortify
will make one for you.
Now you can use the ggResidpanel
package developed for creating ggplot type residual plots on CRAN. You can find the intro tutorial here!