
Last chance! 50% off unlimited learning
Sale ends in
A generic plot-method for ggeffects
-objects.
# S3 method for ggeffects
plot(x, ci = TRUE, facets, rawdata = FALSE,
colors = "Set1", alpha = 0.15, dodge = 0.1, use.theme = TRUE,
dot.alpha = 0.5, jitter = 0.2, log.y = FALSE, case = NULL,
show.legend = TRUE, show.title = TRUE, show.x.title = TRUE,
show.y.title = TRUE, dot.size = NULL, line.size = NULL, ...)
An object of class ggeffects
, as returned by the functions
from this package.
Logical, if TRUE
, confidence bands (for continuous variables
at x-axis) resp. error bars (for factors at x-axis) are plotted. May
also be a character vector with either ci = "dash"
or ci = "dot"
,
to plot dashed or dotted lines instead of a ribbon for confidence bands.
For ggeffects
-objects from ggpredict()
with argument
full.data = TRUE
, ci
is automatically set to FALSE
.
Logical, defaults to TRUE
, if x
has a column named
facet
, and defaults to FALSE
, if x
has no such
column. Set facets = TRUE
to wrap the plot into facets even
for grouping variables (see 'Examples').
Logical, if TRUE
, a layer with raw data from response by
predictor on the x-axis, plotted as point-geoms, is added to the plot.
Character vector with color values in hex-format, valid
color value names (see demo("colors")
or a name of a
color brewer palette.
Following options are valid for colors
:
If not specified, the color brewer palette "Set1" will be used.
If "gs"
, a greyscale will be used.
If "bw"
, the plot is black/white and uses different line types to distinguish groups.
If colors
is any valid color brewer palette name, the related palette will be used. Use display.brewer.all
to view all available palette names.
Else specify own color values or names as vector (e.g. colors = c("#f00000", "#00ff00")
).
Alpha value for the confidence bands.
Value for offsetting or shifting error bars, to avoid overlapping. Only applies, if a factor is plotted at the x-axis; in such cases, the confidence bands are replaced by error bars.
Logical, if TRUE
, a slightly tweaked version of ggplot's
minimal-theme is applied to the plot. If FALSE
, no theme-modifications
are applied.
Alpha value for data points, when rawdata = TRUE
.
Numeric, between 0 and 1. If not NULL
and
rawdata = TRUE
, adds a small amount of random variation to
the location of data points dots, to avoid overplotting. Hence the
points don't reflect exact values in the data. For binary outcomes,
raw data is never jittered to avoid that data points exceed the axis
limits.
Logical, if TRUE
, the y-axis scale is log-transformed.
This might be useful for binomial models with predicted probabilities on
the y-axis.
Desired target case. Labels will automatically converted into the
specified character case. See convert_case
for
more details on this argument.
Logical, shows or hides the plot legend.
Logical, shows or hides the plot title-
Logical, shows or hides the plot title for the x-axis.
Logical, shows or hides the plot title for the y-axis.
Numeric, size of the point geoms.
Numeric, size of the line geoms.
Further arguments passed down to ggplot::scale_y*()
, to
control the appearance of the y-axis.
A ggplot2-object.
ggpredict()
with argument full.data = FALSE
computes
marginal effects at the mean, where covariates are held constant. In
this case, the slope between groups does not vary and the standard
errors and confidence intervals have the same "trend" as the predicted
values. Hence, plotting confidence bands or error bars is possible.
However, ggpredict()
with argument full.data = TRUE
,
covariates and standard errors vary between groups, so plotting
confidence bands and error bars would follow a "winding" shape,
while the predicted values are smoothened by geom_smooth
.
Predicted values and confidence bands or error bars would no
longer match, thus, ci
is automatically set to FALSE
in such cases. You still may want to plot objects returned by
ggpredict()
with argument full.data = TRUE
to additionally
plot the raw data points, which is automatically done.
For ggaverage()
, which computes average marginal effects,
the same problem with standard errors and confidence bands would
apply. However, the standard errors for the average marginal effects
are taken from the marginal effects at the mean, and the predicted
values from the average marginal effects are used to compute
another regression on these values, to get the "smoothened" values
that are used to compute standard errors and confidence intervals
that match the predicted values of the average marginal effects
(maybe, at this point, it is helpful to inspect the code to better
understand what is happening...).
For proportional odds logistic regression (see polr
)
or cumulative link models in general, plots are automatically facetted
by response.level
, which indicates the grouping of predictions
based on the level of the model's response.
# NOT RUN {
library(sjlabelled)
data(efc)
efc$c172code <- as_label(efc$c172code)
fit <- lm(barthtot ~ c12hour + neg_c_7 + c161sex + c172code, data = efc)
dat <- ggpredict(fit, terms = "c12hour")
plot(dat)
dat <- ggpredict(fit, terms = "c12hour", full.data = TRUE)
plot(dat)
dat <- ggaverage(fit, terms = "neg_c_7")
plot(dat)
plot(dat, ci = "dash")
# facet by group
dat <- ggpredict(fit, terms = c("c12hour", "c172code"))
plot(dat, facet = TRUE)
# don't use facets, b/w figure, w/o confidence bands
dat <- ggaverage(fit, terms = c("c12hour", "c172code"))
plot(dat, colors = "bw", ci = FALSE)
# factor at x axis, plot exact data points and error bars
dat <- ggpredict(fit, terms = c("c172code", "c161sex"))
plot(dat)
# for three variables, automatic facetting
dat <- ggpredict(fit, terms = c("c12hour", "c172code", "c161sex"))
plot(dat)
# }
Run the code above in your browser using DataLab