Default plots contain a confidence band, prediction line, and partial residuals. Factors,
transformations, conditioning, interactions, and a variety of other options are supported. The
plot.visreg() function accepts a visreg object as calculated by visreg() and creates the
plot.
# S3 method for visreg
plot(
x,
overlay = FALSE,
print_cond = FALSE,
partial = identical(x$meta$trans, I),
band = TRUE,
rug = 0,
jitter = FALSE,
strip_names = is.numeric(x$fit[, x$meta$by]),
top = c("line", "points"),
line = NULL,
fill = NULL,
points = NULL,
gg = TRUE,
...
)# S3 method for visreg_list
plot(x, ...)
# S3 method for visreg_plot_list
print(x, ...)
A ggplot object, or if x is a visreg_list(), a list of ggplot objects.
A visreg or visreg_list object; see visreg().
By default, when by is specified, separate panels are used to display each
cross-section. If overlay=TRUE, these cross-sections are overlaid on top of each other in a
single plot.
If print_cond=TRUE, the explanatory variable values conditioned on in a
conditional plot are printed to the console (default: FALSE). If print_cond=TRUE and
type="contrast", the conditions will still be printed, but they have no bearing on the plot
unless interactions are present.
If partial=TRUE (the default), partial residuals are shown on the plot.
If band=TRUE (the default), confidence bands are shown on the plot.
Controls the appearance of a rug along the horizontal axis:
rug=0/FALSE: No rug (default)
rug=1/TRUE: Basic rug is drawn along the bottom axis
rug=2: Separate rugs drawn on the top for observations with positive residuals and
on the bottom for observations with negative residuals.
If jitter=TRUE, a small amount of random noise is added to the horizontal
position of partial residuals (and, if drawn, the rug). Potentially useful if many
observations have exactly the same value. Only applies when xvar is continuous; for factor
xvar, the horizontal spacing of points is already controlled by visreg and this argument
has no effect. Default is FALSE.
When by=TRUE, strip_names=TRUE adds the name of the by variable to the
strip at the top of each panel. Default is FALSE for factors and TRUE for numeric by
variables. strip_names can also be a character vector, in which case it replaces the strip
names altogether with values chosen by the user.
By default, the fitted line is plotted on top of the partial residuals; usually this
is preferable, but it does run the risk of obscuring certain residuals. To change this behavior
and plot the partial residuals on top, specify top='points'.
List of parameters to pass to ggplot2::geom_line() (continuous xvar) or
ggplot2::geom_crossbar() (factor xvar) when the fitted line is plotted.
List of parameters to pass to ggplot2::geom_ribbon() (continuous xvar) or
ggplot2::geom_crossbar() (factor xvar) when shaded confidence regions are plotted.
List of parameters to pass to ggplot2::geom_point() (continuous xvar) or
ggplot2::geom_jitter() (factor xvar) when partial residuals are plotted.
Deprecated, no longer has any effect.
Not used; present only because plot() is a generic function. An error is raised if
any arguments are passed here.
If x is a visreg_list(), plot.visreg_list() is dispatched instead; it simply calls
plot.visreg() on each element in turn, passing along the same arguments to each element.
Breheny P and Burchett W. (2017) Visualization of regression models using visreg. R Journal, 9: 56-71. tools:::Rd_expr_doi("10.32614/RJ-2017-046")
visreg2d for creating visreg objects, and the
options vignette for examples.
fit <- lm(Ozone ~ Solar.R + Wind + Temp, data = airquality)
visreg(fit, "Wind")
# Changing appearance
visreg(fit, "Wind", line = list(color = "red"), points = list(size = 2))
Run the code above in your browser using DataLab