plot_shap_bar function

SHAP importance bar plot

SHAP importance bar plot

plot_shap_bar( shap, x, sort = TRUE, labels = c("Negative", "Positive"), top = NULL )

Arguments

  • shap: a matrix of SHAP values
  • x: a matrix or dataframe of feature values containing only features values from the training data. The rows must match rows in shap. If a dataframe is supplied it is converted to a numeric matrix using data.matrix().
  • sort: Logical whether to sort predictors by mean absolute SHAP value
  • labels: Character vector of labels for directionality
  • top: Sets a limit on the number of variables plotted or NULL to plot all variables. If top is set then variables are sorted and sort is overrode.

Returns

A ggplot2 plot

  • Maintainer: Myles Lewis
  • License: MIT + file LICENSE
  • Last published: 2025-03-10