A generic plot-method for ggeffects-objects.

# S3 method for ggeffects
plot(
  x,
  ci = TRUE,
  ci.style = c("ribbon", "errorbar", "dash", "dot"),
  facets,
  add.data = FALSE,
  limit.range = FALSE,
  residuals = FALSE,
  residuals.line = FALSE,
  collapse.group = FALSE,
  colors = "Set1",
  alpha = 0.15,
  dodge = 0.25,
  use.theme = TRUE,
  dot.alpha = 0.35,
  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,
  connect.lines = FALSE,
  grid,
  one.plot = TRUE,
  rawdata,
  residuals.type,
  ...
)

theme_ggeffects(base_size = 11, base_family = "")

show_pals()

Arguments

x

An object of class ggeffects, as returned by the functions from this package.

ci

Logical, if TRUE, confidence bands (for continuous variables at x-axis) resp. error bars (for factors at x-axis) are plotted.

ci.style

Character vector, indicating the style of the confidence bands. May be either "ribbon", "errorbar", "dash" or "dot", to plot a ribbon, error bars, or dashed or dotted lines as confidence bands.

facets, grid

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'). grid is an alias for facets.

add.data, rawdata

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.

limit.range

Logical, if TRUE, limits the range of the prediction bands to the range of the data.

residuals

Logical, if TRUE, a layer with partial residuals is added to the plot. See vignette "Effect Displays with Partial Residuals" from effects for more details on partial residual plots.

residuals.line

Logical, if TRUE, a loess-fit line is added to the partial residuals plot. Only applies if residuals is TRUE.

collapse.group

For mixed effects models, name of the grouping variable of random effects. If collapse.group = TRUE, data points "collapsed" by the first random effect groups are added to the plot. Else, if collapse.group is a name of a group factor, data is collapsed by that specific random effect. See collapse_by_group for further details.

colors

Character vector with color values in hex-format, valid color value names (see demo("colors")) or a name of a ggeffects-color-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.

  • There are some pre-defined color-palettes in this package that can be used, e.g. colors = "metro". See show_pals() to show all available palettes.

  • Else specify own color values or names as vector (e.g. colors = c("#f00000", "#00ff00")).

alpha

Alpha value for the confidence bands.

dodge

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 automatically), or if ci.style = "errorbars".

use.theme

Logical, if TRUE, a slightly tweaked version of ggplot's minimal-theme, theme_ggeffects(), is applied to the plot. If FALSE, no theme-modifications are applied.

dot.alpha

Alpha value for data points, when add.data = TRUE.

jitter

Numeric, between 0 and 1. If not NULL and add.data = 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. May also be a numeric vector of length two, to add different horizontal and vertical jittering. For binary outcomes, raw data is not jittered by default to avoid that data points exceed the axis limits.

log.y

Logical, if TRUE, the y-axis scale is log-transformed. This might be useful for binomial models with predicted probabilities on the y-axis.

case

Desired target case. Labels will automatically converted into the specified character case. See ?sjlabelled::convert_case for more details on this argument.

show.legend

Logical, shows or hides the plot legend.

show.title

Logical, shows or hides the plot title-

show.x.title

Logical, shows or hides the plot title for the x-axis.

show.y.title

Logical, shows or hides the plot title for the y-axis.

dot.size

Numeric, size of the point geoms.

line.size

Numeric, size of the line geoms.

connect.lines

Logical, if TRUE and plot has point-geoms with error bars (this is usually the case when the x-axis is discrete), points of same groups will be connected with a line.

one.plot

Logical, if TRUE and x has a panel column (i.e. when four terms were used), a single, integrated plot is produced.

residuals.type

Deprecated. Formally was the residual type. Now is always "working".

...

Further arguments passed down to ggplot::scale_y*(), to control the appearance of the y-axis.

base_size

Base font size.

base_family

Base font family.

Value

A ggplot2-object.

Details

For proportional odds logistic regression (see ?MASS::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.

Note

Load library(ggplot2) and use theme_set(theme_ggeffects()) to set the ggeffects-theme as default plotting theme. You can then use further plot-modifiers from sjPlot, like legend_style() or font_size() without losing the theme-modifications.

There are pre-defined colour palettes in this package. Use show_pals() to show all available colour palettes.

Partial Residuals

For generalized linear models (glms), residualized scores are computed as inv.link(link(Y) + r) where Y are the predicted values on the response scale, and r are the working residuals.

For (generalized) linear mixed models, the random effect are also partialled out.

Examples

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)
# \donttest{ # facet by group, use pre-defined color palette dat <- ggpredict(fit, terms = c("c12hour", "c172code")) plot(dat, facet = TRUE, colors = "hero")
# don't use facets, b/w figure, w/o confidence bands dat <- ggpredict(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)# }
# show all color palettes show_pals()