Learn R Programming

projoint (version 1.0.6)

plot_projoint_choice_level_mm: Plot choice-level marginal means (MMs) (helper)

Description

Internal helper used by plot.projoint_results to render choice-level marginal means (MMs). Supports a bar chart or a horizontal pointrange layout and optional custom level labels.

Usage

plot_projoint_choice_level_mm(
  x,
  .type = "pointrange",
  .estimates = "corrected",
  .labels = NULL,
  .show_attribute = TRUE,
  .remove_xaxis = FALSE,
  .xlim = c(0, 1),
  .plot.margin = c(top = 1, left = 2, bottom = 1, right = 2),
  ...
)

Value

A ggplot2 object.

Arguments

x

A projoint_results object produced by projoint with structure = "choice_level" and estimand = "mm".

.type

Character. Either "bar" (two bars with CIs) or "pointrange" (horizontal estimate with CI and level labels at the extremes). Default "pointrange".

.estimates

Character. Which estimate version to plot: "corrected" (default) or "uncorrected".

.labels

Optional character vector of length 2 for custom level labels (left/right). If NULL, labels are derived from x$labels.

.show_attribute

Logical; if TRUE (default), add the attribute name as the title when both levels are from the same attribute.

.remove_xaxis

Logical; if TRUE, remove x-axis line, ticks, and labels (useful when embedding). Default FALSE.

.xlim

Numeric length-2 giving the x-axis limits. Default c(0, 1).

.plot.margin

Numeric vector of plot margins in cm, c(top, left, bottom, right). Default c(1, 2, 1, 2).

...

Currently unused (reserved for future extensions).

Details

This helper expects that the projoint_results object already contains a single pair of choice-level MMs (i.e., one att_level_choose and one att_level_notchoose). It is called internally by plot.projoint_results when x$structure == "choice_level" and x$estimand == "mm".

When .type = "pointrange", the level labels are placed just outside .xlim to avoid overlap with the confidence interval. If the two levels correspond to different attributes, the attribute title is omitted and a message is emitted.

See Also

plot.projoint_results for the user-facing plot method.

Examples

Run this code
data(exampleData1)
dat <- reshape_projoint(exampleData1,
  .outcomes = c("choice1", "choice2", "choice1_repeated_flipped")
)
att <- unique(dat$labels$attribute_id)[1]
levs <- subset(dat$labels, attribute_id == att)$level_id
lev_names <- sub(".*:", "", levs)
q <- set_qoi("choice_level", "mm",
  .att_choose = att, .lev_choose = lev_names[2],
  .att_notchoose = att, .lev_notchoose = lev_names[1]
)
fit <- projoint(dat, .qoi = q)
plot(fit)

Run the code above in your browser using DataLab