Skip to contents

Computes cohort-level means for the public/private components of a list experiment model (via lx_predict_for_cohorts()) and passes them to g6tr_dumbbell_plot_2(). For a cohort_set, each row is a cohort and the y-axis labels are built from the cohort set columns (excluding list columns, n, and weighted_n). For a single cohort (or NULL), a one-row plot is returned.

Usage

lx_dumbbell_plot(
  model,
  cohorts = NULL,
  color_by = NULL,
  name_by = NULL,
  icon_style = style_icon(icon = c("", ""), fontface = c("plain", "bold")),
  label_style = style_text(size = 5),
  segment_style = style_segment_alpha_gradient(alpha_1 = 0, alpha_2 = 1, gamma = 1, n =
    300),
  x_reference = style_reference_line(),
  colors = NULL
)

# S3 method for class '`NULL`'
lx_dumbbell_plot(
  model,
  cohorts = NULL,
  color_by = NULL,
  name_by = NULL,
  icon_style = style_icon(icon = c("", ""), fontface = c("plain", "bold"), size =
    6),
  label_style = style_text(size = 5),
  segment_style = style_segment_alpha_gradient(alpha_1 = 0, alpha_2 = 1, gamma = 1, n =
    300),
  x_reference = style_reference_line(),
  colors = NULL
)

# S3 method for class 'character'
lx_dumbbell_plot(
  model,
  cohorts,
  color_by = NULL,
  name_by = NULL,
  icon_style = style_icon(icon = c("", ""), fontface = c("plain", "bold"), size =
    6),
  label_style = style_text(size = 5),
  segment_style = style_segment_alpha_gradient(alpha_1 = 0, alpha_2 = 1, gamma = 1, n =
    300),
  x_reference = style_reference_line(),
  colors = NULL
)

# S3 method for class 'cohort'
lx_dumbbell_plot(
  model,
  cohorts,
  color_by = NULL,
  name_by = NULL,
  icon_style = style_icon(icon = c("", ""), fontface = c("plain", "bold"), size =
    6),
  label_style = style_text(size = 5),
  segment_style = style_segment_alpha_gradient(alpha_1 = 0, alpha_2 = 1, gamma = 1, n =
    300),
  x_reference = style_reference_line(),
  colors = NULL
)

# S3 method for class 'cohort_set'
lx_dumbbell_plot(
  model,
  cohorts,
  color_by = NULL,
  name_by = NULL,
  icon_style = style_icon(icon = c("", ""), fontface = c("plain", "bold"), size =
    6),
  label_style = style_text(size = 5),
  segment_style = style_segment_alpha_gradient(alpha_1 = 0, alpha_2 = 1, gamma = 1, n =
    300),
  x_reference = style_reference_line(),
  colors = NULL
)

Arguments

model

An lx_model object.

cohorts

A cohort, cohort_set, NULL for the whole population, "predictors" (all predictors + population), "population" (population-only), or a character vector of predictor names. Include "population" in an explicit vector when you also want the overall population cohort.

color_by

Optional unquoted column used for categorical coloring. Only supported when cohorts is a cohort_set.

name_by

Optional unquoted column from a cohort set used to build the y-axis labels. Only supported when cohorts is a cohort_set.

icon_style

A 2-row data frame returned by style_icon().

label_style

A named list returned by style_text().

segment_style

A named list returned by either style_segment() or style_segment_alpha_gradient().

x_reference

Optional named list returned by style_reference_line(). Defaults to style_reference_line(). Set to NULL to omit the vertical line.

colors

Optional character vector of colors passed through to g6tr_dumbbell_plot_2().

Value

A ggplot object.

Examples

model_pets <- example_lx_model

# Whole population
p1 <- lx_dumbbell_plot(model_pets)
#> ℹ No weights provided. Using equal weights of 1.
#> ! Font Awesome not found on the system; falling back to the default font family "DejaVu Sans". If Font Awesome is installed, inspect `systemfonts::system_fonts()` to find the correct family name.
#> ! Font family "Open Sans" not found; using default family "DejaVu Sans".

# Cohort set with coloring by a cohort-set column
cohort_set <- example_srv_lx |>
  dplyr::filter(!is.na(d_gender)) |>
  g6tr.cohorts::create_cohort_set(
    id_col = response_id,
    grp_cols = c(d_gender),
    weight_col = weight
  )
p2 <- lx_dumbbell_plot(model_pets, cohorts = cohort_set, color_by = level, name_by = level)
#> ! Font Awesome not found on the system; falling back to the default font family "DejaVu Sans". If Font Awesome is installed, inspect `systemfonts::system_fonts()` to find the correct family name.
#> ! Font family "Open Sans" not found; using default family "DejaVu Sans".

if (interactive()) {
  print(p1)
  print(p2)
}