Versatile plot function for an "EffectData" object. By default, all calculated
statistics (except "resid_mean") are shown. To select certain statistics,
use the stats
argument. Set plotly = TRUE
for interactive plots. Note that
all statistics are plotted at bin means, except for ALE
(shown at right bin breaks).
# S3 method for class 'EffectData'
plot(
x,
stats = NULL,
ncol = grDevices::n2mfrow(length(x))[2L],
byrow = TRUE,
share_y = c("no", "all", "rows", "cols"),
ylim = NULL,
discrete_lines = TRUE,
continuous_points = FALSE,
title = "",
subplot_titles = TRUE,
ylab = NULL,
legend_labels = NULL,
interval = c("no", "ci", "ciw", "sd"),
ci_level = 0.95,
colors = getOption("effectplots.colors"),
fill = getOption("effectplots.fill"),
alpha = 1,
bar_height = 1,
bar_width = 1,
bar_measure = c("weight", "N"),
wrap_x = 10,
rotate_x = 0,
plotly = getOption("effectplots.plotly"),
...
)
An object of class "EffectData".
Vector of statistics to show. The default NULL
equals either
c("y_mean", "pred_mean", "pd", "ale")
, or "resid_mean"
(when x
results from bias()
). Only available statistics are shown.
Additionally, this argument controls the order used to plot the lines.
Number of columns of the plot layout, by default
grDevices::n2mfrow(length(x))[2L]
. Only relevant for multiple plots.
Should plots be placed by row? Default is TRUE
.
Only for multiple plots.
Should y axis be shared across subplots? The default is "no".
Other choices are "all", "rows", and "cols". Note that this currently does not
take into account error bars/ribbons.
Has no effect if ylim
is passed. Only for multiple plots.
A vector of length 2 with manual y axis limits, or a list thereof.
Show lines for discrete features. Default is TRUE
.
Show points for continuous features. Default is FALSE
.
Overall plot title, by default ""
(no title).
Should variable names be shown as subplot titles?
Default is TRUE
. Only for multiple plots.
Label of the y axis. The default NULL
automatically derives
a reasonable name.
Vector of legend labels in the same order as the
statistics plotted, or NULL
(default).
What intervals should be shown for observed y and residuals? One of
"no" (default),
"ci": Z confidence intervals using sqrt(N) as standard error of the mean,
"ciw": Like "ci", but using sqrt(weight) as standard error of the mean, or
"sd": standard deviations. Ribbons for continuous features, and error bars otherwise.
The nominal level of the Z confidence intervals (only when
error
equals "ci" or "ciw"). The default is 0.95.
Vector of line/point colors of sufficient length.
By default, a color blind friendly palette from "ggthemes".
To change globally, set options(effectplots.colors = new colors)
.
Fill color of bars. The default equals "lightgrey".
To change globally, set options(effectplots.fill = new color)
.
Alpha transparency of lines and points. Default is 1.
Relative bar height (default 1). Set to 0 for no bars.
Bar width multiplier (for discrete features). By default 1.
What should bars represent? Either "weight" (default) or "N".
Should categorical x axis labels be wrapped after this length?
The default is 10. Set to 0 for no wrapping. Vectorized over x
.
Only for "ggplot2" backend.
Should categorical xaxis labels be rotated by this angle?
The default is 0 (no rotation). Vectorized over x
. Only for "ggplot2" backend.
Should 'plotly' be used? The default is FALSE
('ggplot2' with
'patchwork'). Use options(effectplots.plotly = TRUE)
to change globally.
Passed to patchwork::plot_layout()
or plotly::subplot()
. Typically
not used.
If a single plot, an object of class "ggplot" or "plotly". Otherwise, an object of class "patchwork", or a "plotly" subplot.
fit <- lm(Sepal.Length ~ ., data = iris)
xvars <- colnames(iris)[-1]
M <- feature_effects(fit, v = xvars, data = iris, y = "Sepal.Length", breaks = 5)
plot(M, share_y = "all")
plot(M, stats = c("pd", "ale"), legend_labels = c("PD", "ALE"))
plot(M, stats = "resid_mean", share_y = "all", interval = "ci")