Skip to contents

Plots output from avg_comparisons() on the comparison scale.

Usage

plot_comparisons(
  x,
  x_var = NULL,
  color_var = NULL,
  linetype_var = NULL,
  facet_var = NULL,
  geom = c("auto", "line", "point"),
  estimate_var = "estimate",
  show_uncertainty = TRUE,
  ribbon_alpha = 0.12,
  point_size = 2,
  line_width = 0.7
)

Arguments

x

A markov_avg_comparisons object returned by avg_comparisons(), optionally after inferences().

x_var

Character string or NULL. X-axis variable. If NULL, uses "time" when available, then "state_set" when available, and otherwise "contrast".

color_var

Character string or NULL. Optional variable mapped to color. If NULL, a useful grouping variable is inferred when needed.

linetype_var

Character string or NULL. Optional variable mapped to linetype for line plots.

facet_var

Character vector or NULL. Optional faceting variable. Use a length-two vector for facet_grid(row ~ column).

geom

Character string. "auto" uses lines when x_var is "time" and points otherwise. Use "line" or "point" to override.

estimate_var

Character string. Column containing comparison estimates.

show_uncertainty

Logical. If TRUE, add confidence ribbons for line plots or intervals for point plots when conf.low and conf.high exist.

ribbon_alpha

Numeric alpha level for confidence ribbons.

point_size

Numeric point size for point plots.

line_width

Numeric line width for lines and interval geoms.

Value

A ggplot object.

Details

The y axis is the contrast scale: difference contrasts are centered on a dashed reference line at 0, and ratio contrasts are centered on a dashed reference line at 1. A single plot must contain only one comparison scale.

Examples

if (FALSE) { # \dontrun{
cmp <- avg_comparisons(
  fit,
  variables = list(tx = c(0, 1)),
  estimand = "time_in_state",
  state_sets = c(1, 2),
  times = 1:30
) |>
  inferences(method = "mvn", n_draws = 500)

plot_comparisons(cmp)
} # }