Introduction: Plotting Adjusted Predictions and Marginal Effects
If you don’t want to write your own ggplot-code,
ggeffects has a
plot()-method with some
convenient defaults, which allows quickly creating ggplot-objects.
plot() has some arguments to tweak the plot-appearance. For
show_ci allows you to show or hide confidence
bands (or error bars, for discrete variables),
allows you to create facets even for just one grouping variable, or
colors allows you to quickly choose from some
color-palettes, including black & white colored plots. Use
show_data to add the raw data points to the plot.
# don't use facets, b/w figure, w/o confidence bands plot(dat, colors = "bw", show_ci = FALSE)
# point-geoms for discrete x-axis can be connected with lines plot(dat, connect_lines = TRUE)
For three grouping variable (i.e. if
terms is of length
four), one plot per
panel (the values of the fourth
terms) is created, and a single, integrated
plot is produced by default. Use
one_plot = FALSE to return
one plot per panel.
In some plots, the the confidence bands are not represented by a
shaded area (ribbons), but rather by error bars (with line), dashed or
dotted lines. Use
ci_style = "errorbar",
ci_style = "dash" or
ci_style = "dot" to
change the style of confidence bands.
For binomial models, the y-axis indicates the predicted probabilities of an event. In this case, error bars are not symmetrical.
Here you can use
log_y to log-transform the y-axis. The
plot()-method will automatically choose axis breaks and
limits that fit well to the value range and log-scale.
# plot with log-transformed y-axis plot(dat, log_y = TRUE)
Furthermore, arguments in
... are passed down to
log_y = TRUE), so
you can control the appearance of the y-axis.
ggpredict() also supports
the survival-package and is able to either plot
risk-scores (the default), probabilities of survival
type = "survival") or cumulative hazards
type = "cumulative_hazard").
Since probabilities of survival and cumulative hazards are changing
across time, the time-variable is automatically used as x-axis in such
cases, so the
terms-argument only needs up to two
The ggeffects-package has a few pre-defined
color-palettes that can be used with the
show_pals() to see all available palettes.
Here are two examples showing how to use pre-defined colors: