Learn R Programming

ggRandomForests (version 3.5.0)

plot.gg_shap: Plot a gg_shap object

Description

Routes to one of three SHAP views. type = "beeswarm" (default) draws the signature SHAP summary; "importance" draws a mean-absolute-SHAP bar chart; "dependence" draws SHAP value against a single feature's value.

Usage

# S3 method for gg_shap
plot(x, type = c("beeswarm", "importance", "dependence"), xvar = NULL, ...)

Value

A ggplot object.

Arguments

x

A gg_shap object.

type

One of "beeswarm", "importance", or "dependence".

xvar

For type = "dependence", the variable to plot. When NULL, the top-ranked variable is used.

...

Passed to the underlying builder.

See Also

gg_shap shap_importance

Examples

Run this code
# \donttest{
if (requireNamespace("kernelshap", quietly = TRUE)) {
  rf <- randomForestSRC::rfsrc(Ozone ~ ., data = na.omit(airquality),
                               ntree = 50)
  gg_dta <- gg_shap(rf, bg_n = 20)
  plot(gg_dta, type = "importance")
}
# }

Run the code above in your browser using DataLab