| Type: | Package |
| Title: | Grammar of Graphics for Linear Model Diagnostic Plots |
| Version: | 1.1.0 |
| Description: | Allows for easy creation of diagnostic plots for a variety of model objects using the Grammar of Graphics. Provides functionality for both individual diagnostic plots and an array of four standard diagnostic plots. |
| License: | CC0 |
| Date: | 2026-08-01 |
| Encoding: | UTF-8 |
| Depends: | ggplot2 |
| Imports: | broom, broom.mixed, patchwork, utils, rlang, vctrs |
| Suggests: | bslib, DT, fivethirtyeight, ggthemes, htmltools, lme4, palmerpenguins, RColorBrewer, shiny, testthat (≥ 3.0.0) |
| URL: | https://github.com/graysonwhite/gglm, https://graysonwhite.com/gglm/ |
| BugReports: | https://github.com/graysonwhite/gglm/issues |
| RoxygenNote: | 7.3.3 |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-08-01 18:04:52 UTC; grwhite |
| Author: | Grayson White |
| Maintainer: | Grayson White <graysonwhite13@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-08-01 18:20:02 UTC |
gglm
Description
Provides four standard visual model diagnostic plots with
ggplot2.
Usage
gglm(data, mapping = ggplot2::aes(), theme = ggplot2::theme_gray(), ...)
Arguments
data |
A model object. |
mapping |
Additional aesthetic mappings to add to each layer, e.g.
|
theme |
The theme of the |
... |
Additional arguments passed on to each |
Value
A ggplot2 object for visual diagnostic of model validity.
Examples
data(mtcars)
m1 <- lm(mpg ~ cyl + disp + hp, data = mtcars)
gglm(m1)
launch
Description
Launches a R Shiny-based applet for linear model diagnostics.
Usage
launch(
data = NULL,
example_datasets = list(penguins = palmerpenguins::penguins, candy =
fivethirtyeight::candy_rankings, mtcars = datasets::mtcars),
...
)
Arguments
data |
A |
example_datasets |
A named |
... |
Currently ignored. For extendability. |
Value
None. Launches a shiny applet for point-and-click based model
diagnostics.
Examples
## Not run:
launch()
## End(Not run)
list_model_classes
Description
Returns the possible model classes that gglm works with.
Usage
list_model_classes(...)
Arguments
... |
Currently ignored. For extendability. |
Value
A character vector containing the possible model classes that
gglm works with.
Note
Note that these are not always the exact name of the class that that
can be used. This is due to how some methods are written in the packages
gglm imports. For example, the model class "merMod" refers to a
variety of model outputs from lme4, even when the outputted class is
not called "merMod".
Examples
list_model_classes()
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- broom
stat_cooks_leverage
Description
Cook's Distance vs. Leverage
Usage
stat_cooks_leverage(
mapping = ggplot2::aes(),
alpha = 0.5,
method = "loess",
linecolor = "steelblue",
se = FALSE,
...
)
Arguments
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
alpha |
Adjust transparency of points. |
method |
Method for fitting the line to the points. |
linecolor |
Color of the line. |
se |
Keep standard error bands around line? |
... |
Additional arguments passed on to |
Value
A ggplot2 layer for plotting Cook's Distance vs. Leverage.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_cooks_leverage()
stat_cooks_obs
Description
ggplot2 layer for plotting cook's distance by observation number.
Usage
stat_cooks_obs(mapping = ggplot2::aes(), ...)
Arguments
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
... |
Additional arguments passed on to |
Value
A ggplot2 layer for plotting cook's distance by observation number.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_cooks_obs()
stat_fitted_resid
Description
ggplot2 layer for plotting a fitted vs. residual scatter plot.
Usage
stat_fitted_resid(mapping = ggplot2::aes(), alpha = 0.5, ...)
Arguments
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
alpha |
Adjust transparency of points. |
... |
Additional arguments passed on to |
Value
A ggplot2 layer for plotting a fitted vs. residual scatter plot.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_fitted_resid()
stat_normal_qq
Description
Normal QQ plot.
Usage
stat_normal_qq(mapping = ggplot2::aes(), alpha = 0.5, ...)
Arguments
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
alpha |
Adjust transparency of points. |
... |
Additional arguments passed on to |
Value
A ggplot2 layer for plotting a Normal Q-Q plot.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_normal_qq()
stat_resid_hist
Description
Visualize the distribution of the residuals of a model.
Usage
stat_resid_hist(mapping = ggplot2::aes(), bins = 30, ...)
Arguments
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
bins |
Adjust the number of bins. |
... |
Additional arguments passed on to |
Value
A ggplot2 layer for plotting a histogram of residuals.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_resid_hist()
stat_resid_leverage
Description
Residual vs. leverage plot.
Usage
stat_resid_leverage(
mapping = ggplot2::aes(),
alpha = 0.5,
method = "loess",
se = FALSE,
linecolor = "steelblue",
...
)
Arguments
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
alpha |
Adjust transparency of points. |
method |
Method for fitting the line to the points. |
se |
Keep standard error bands around line? |
linecolor |
Color of the line. |
... |
Additional arguments passed on to |
Value
A ggplot2 layer for plotting a fitted vs. residual scatter plot.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_resid_leverage()
stat_scale_location
Description
Scale location diagnostic plot.
Usage
stat_scale_location(
mapping = ggplot2::aes(),
alpha = 0.5,
na.rm = TRUE,
se = FALSE,
method = "loess",
linecolor = "steelblue",
...
)
Arguments
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
alpha |
Adjust the transparency of points. |
na.rm |
Remove points with value NA? |
se |
Keep standard error bands around line? |
method |
Method for fitting the line to the points. |
linecolor |
Color of the line. |
... |
Additional arguments passed on to |
Value
A ggplot2 layer for plotting the scale location diagnostic plot.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_scale_location()