marginsplot: Plot predictive margins

View source: R/postestimation.R

marginsplotR Documentation

Plot predictive margins

Description

Plots estimates and confidence intervals from margins().

Usage

marginsplot(
  result = NULL,
  x = NULL,
  by = NULL,
  ci = TRUE,
  line = TRUE,
  points = TRUE,
  line_width = 2,
  line_type = 1,
  point_size = 1,
  point_pch = 16,
  ci_color = NULL,
  ci_alpha = 1,
  ci_lwd = 1,
  ci_lty = 1,
  xline = NULL,
  yline = NULL,
  ref_color = "gray40",
  ref_lty = 2,
  ref_lwd = 1,
  xlab = NULL,
  ylab = NULL,
  xtitle = NULL,
  ytitle = NULL,
  title = NULL,
  subtitle = NULL,
  note = NULL,
  color = NULL,
  palette = "journal",
  alpha = 1,
  legend = TRUE,
  legend_position = "topright",
  theme = "journal",
  size = 11,
  file = NULL,
  width = 7,
  height = 5,
  dpi = 300,
  show = TRUE,
  bg = "white",
  vline = NULL,
  hline = NULL
  )

Arguments

result

A margins() result. The most recent margins result is used when omitted.

x

Scenario variable for the horizontal axis; selected automatically when omitted.

by

Optional grouping variable from the margins table.

ci

Draw confidence intervals.

line, points

Draw connecting lines and points.

xline, yline

Optional reference lines at x- and y-axis values.

vline, hline

Deprecated aliases for xline and yline.

ref_color, ref_lty, ref_lwd

Reference-line formatting.

xlab, ylab, xtitle, ytitle, title, subtitle, note, color, palette, alpha, legend, legend_position, theme, size, file, width, height, dpi, show, bg

Standard R4VN graph controls.

line_width, line_type

Connecting-line width and line type.

point_size, point_pch

Point size and symbol.

ci_color, ci_alpha, ci_lwd, ci_lty

Confidence-interval colour, transparency, width, and line type. ci_color = NULL follows each group colour.

Value

An R4VN result object, invisibly.

See Also

margins

Examples

d <- data.frame(
  outcome = factor(c(0, 0, 0, 1, 0, 1, 1, 1), levels = 0:1,
                   labels = c("No", "Yes")),
  age = c(20, 25, 30, 35, 40, 45, 50, 55)
)
m <- logistic(outcome, c.age, data = d, event = "Yes", show = FALSE)
mg <- margins(m, at = at(age = seq(30, 50, 10)), show = FALSE)
marginsplot(mg, show = FALSE)

R4VN documentation built on Sept. 30, 2026, 5:13 p.m.