View source: R/fortify-models.R
fortify.lm | R Documentation |
This method is deprecated because using broom::augment()
is a better
solution to supplement data from a linear model.
If you have missing values in your model data, you may need to refit
the model with na.action = na.exclude
.
## S3 method for class 'lm'
fortify(model, data = model$model, ...)
model |
linear model |
data |
data set, defaults to data used to fit model |
... |
not used by this method |
The original data with extra columns:
.hat |
Diagonal of the hat matrix |
.sigma |
Estimate of residual standard deviation when corresponding observation is dropped from model |
.cooksd |
Cooks distance, |
.fitted |
Fitted values of model |
.resid |
Residuals |
.stdresid |
Standardised residuals |
mod <- lm(mpg ~ wt, data = mtcars)
# Show augmented model
head(augment(mod))
head(fortify(mod))
# Using augment to convert model to ready-to-plot data
ggplot(augment(mod), aes(.fitted, .resid)) +
geom_point() +
geom_hline(yintercept = 0) +
geom_smooth(se = FALSE)
# Colouring by original data not included in the model
ggplot(augment(mod, mtcars), aes(.fitted, .std.resid, colour = factor(cyl))) +
geom_point()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.