gglm, The Grammar of Graphics for Linear Model
Diagnostics, is a package that creates beautiful
plots for linear models that are easy to use and adhere to The Grammar
of Graphics. The purpose of this package is to provide a sensible
alternative to using the base-R
plot() function to produce diagnostic
plots for linear models.
# Currently, the best way to install is from GitHub. devtools::install_github("graysonwhite/gglm")
gglm has two main types of functions. First, the
gglm() function for
quickly creating the four main diagnostic plots, similar to when you
plot() on an
lm type object. Second, the
which produce diagnostic plots the align with The Grammar of Graphics by
ggplot2 layers that allow for easy plotting of particular
model diagnostic plots.
library(gglm) # Load the package data(mtcars) # Load example data model <- lm(mpg ~ ., data = mtcars) # Create your model gglm(model) # Plot the four main diagnostic plots
library(ggplot2) # Need to load ggplot2 ggplot(data = model) + stat_fitted_resid()
# We can also add layers such as themes to these `ggplot`s and adjust features of the plot: ggplot(data = model) + stat_cooks_leverage(alpha = 1) + theme_minimal()
gglm() plots the four default diagnostic plots when supplied an
object. This function works similarly to
plot.lm(), except that it
displays the four diagnostic plots at once.
stat_resid_leverage() all are
ggplot2 layers used to create
individual diagnostic plots. To use these, follow Example 2.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.