gg_diagnose: Plot all diagnostic plots given fitted linear regression...

View source: R/gg_diagnose.R

gg_diagnoseR Documentation

Plot all diagnostic plots given fitted linear regression line.

Description

Plot all diagnostic plots given fitted linear regression line.

Usage

gg_diagnose(
  fitted.lm,
  theme = NULL,
  ncol = NA,
  plot.all = TRUE,
  mode = "all",
  scale.factor = 0.5,
  boxcox = FALSE,
  max.per.page = NA
)

Arguments

fitted.lm

lm object that contains fitted regression

theme

ggplot graphing style using 'ggplot::theme()'. A ggplot graphing style to apply to all plots. Default to null.

ncol

specify number of columns in resulting plot per page. Default to make a square matrix of the output.

plot.all

logical; determine whether plot will be returned as an arranged grid. When set to false, the function will return a list of diagnostic plots. Parameter defaults to TRUE.

mode

A string. Specifies which set of diagnostic plots to return: * 'all' (the default) * 'base_r': only graphs included in the base R 'plot(lm(...))' (i.e. residual vs fitted, QQ plot, scale location, residual vs leverage)

scale.factor

numeric; scales the point size, linewidth, labels in all diagnostic plots to allow optimal viewing. Defaults to 0.5.

boxcox

logical; detemine whether boxcox plot will be included. Parameter defaults to FALSE.

max.per.page

numeric; maximum number of plots allowed in one page.

Value

An arranged grid of linear model diagnostics plots in ggplot. If plot.all is set to FALSE, a list of ggplot objects will be returned instead. Name of the plots are set to respective variable names.

Examples

library(MASS)
data(Cars93)
# a regression with categorical variable
cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93)
gg_diagnose(cars_lm)
# customize which diagnostic plot is included
plots <- gg_diagnose(cars_lm, plot.all = FALSE)
names(plots)     # get name of the plots
exclude_plots <- plots[-c(1, 3) ]    #exclude certain diagnostics plots
include_plots <- plots[c(1, 3)]      # include certain diagnostics plots
plot_all(exclude_plots)              # make use of plot_all() in lindia
plot_all(include_plots)

yeukyul/lindia documentation built on Aug. 26, 2023, 1:35 a.m.