Skip to contents

Generate a SHAP summary plot to visualize the distribution, direction, and magnitude of SHAP values for the top contributing features in a spatial transcriptomics model.

Usage

SpaPheno_SHAP_summary_plot(shap_df, top_n = 10)

Arguments

shap_df

A data.frame containing SHAP values. Must include at least the columns: feature, phi (SHAP value), and feature.value.

top_n

Integer; number of top features to include in the plot. Default is 10.

Value

A ggplot2 object displaying a SHAP summary plot for top features.

Details

The function selects the top `n` features ranked by mean absolute SHAP value, and displays a scatter plot of their SHAP contributions. Each point is colored by the corresponding feature value, allowing joint interpretation of importance and directionality.

Author

Bin Duan

Examples

if (FALSE) { # \dontrun{
data("osmFISH_metadata_cellType")
data("osmFISH_bulk_decon")
data("osmFISH_bulk_pheno")
data("osmFISH_bulk_coordinate")

PhenoResult <- SpatialPhenoMap(
  bulk_decon = osmFISH_bulk_decon,
  bulk_pheno = osmFISH_bulk_pheno,
  family = "binomial",
  coord = osmFISH_bulk_coordinate,
  resolution = "single_cell",
  sample_information_cellType = osmFISH_metadata_cellType
)

pred_result <- PhenoResult$pred_score
phenoPlus <- row.names(pred_result[pred_result$label %in% "phenotype+", ])
model <- PhenoResult$model
X <- as.data.frame(PhenoResult$cell_type_distribution[phenoPlus, ])

# This step took a very long time
shap_test_plus <- compute_shap_spatial(
  model = model,
  X_bulk = as.data.frame(osmFISH_bulk_decon),
  y_bulk = osmFISH_bulk_pheno,
  X_spatial = X)

SpaPheno_SHAP_summary_plot(shap_test_plus, top_n = 31)

} # }