Skip to contents

Plot waterfall-style SHAP contributions for explicitly selected perturbations and samples. Training samples are used by default. Set source = "user" to plot samples predicted with add_powerup_predictions().

Usage

plot_contributions_to_sample(
  models,
  prepared,
  perturbations,
  samples,
  source = "training",
  n_features = 5,
  n_columns = 1,
  short_title = FALSE,
  fixed_axis = FALSE,
  axis_limits = c(-0.05, 1),
  nudges_lr = c(0, 0),
  values_are_percentages = TRUE,
  show_error = FALSE,
  highlight_significant = FALSE,
  labels_data = NULL,
  sec_label = NULL
)

Arguments

models

A named list of models returned by fit_powerup_models().

prepared

The prepared POWERUP object used for model training and prediction.

perturbations

Character vector of perturbation names to plot.

samples

Character vector of sample names to plot.

source

Either "training" (default) or "user".

n_features

Number of top feature contributions to show individually. Remaining contributions are combined.

n_columns

Number of columns in the resulting plot grid.

short_title

If TRUE, use a compact plot title.

fixed_axis

If TRUE, use axis_limits for every plot.

axis_limits

Numeric vector of length two used when fixed_axis = TRUE.

nudges_lr

Numeric vector of length two controlling contribution-label nudges.

values_are_percentages

If TRUE, display predictions and contributions as percentages.

show_error

If TRUE, shade the central 50 and 80 percent prediction intervals and show the 95 percent interval with dashed boundaries.

highlight_significant

If TRUE, highlight plots whose prediction interval supports the modeled event.

labels_data

Optional data frame containing old_label and new_label columns for perturbation-label replacement.

sec_label

If non-NULL, use labels_data$second_label as the subtitle for mapped perturbations.

Value

A combined ggplot object containing one waterfall plot per selected perturbation and sample.

Examples

if (FALSE) { # \dontrun{
plot_contributions_to_sample(
  models,
  prepared,
  perturbations = "CTNNB1",
  samples = "ACH-000957"
)

models <- add_powerup_predictions(models, prepared)
plot_contributions_to_sample(
  models,
  prepared,
  perturbations = "CTNNB1",
  samples = "ACH-000957",
  source = "user"
)
} # }