One horizontal swarm per feature showing every observation's SHAP value, with points nudged vertically so overlapping values stay countable. Color the points by the feature value to read the direction of effect.

geom_shap(mapping = NULL, data = NULL, size = NULL, alpha = NULL)

Arguments

mapping, data

Standard layer overrides. Map the SHAP value to x and the feature name to y; map color to the feature value.

size

Point radius in px.

alpha

Point opacity.

Value

A Layer to add with +.

Examples

set.seed(1)
d <- data.frame(
  feature = rep(c("age", "income", "tenure"), each = 40),
  shap = c(rnorm(40, 0.3, 0.2), rnorm(40, -0.1, 0.3), rnorm(40, 0, 0.15)),
  value = runif(120)
)
ggnext(d, aes(shap, feature, color = value)) +
  geom_shap() +
  geom_vline(0, dash = "3,3") +
  labs(title = "SHAP value by feature", x = "SHAP value", y = NULL)
#> <ggnext plot>
#>   data:  120 x 3
#>   aes:   x = shap, y = feature, color = value
#>   layers: 2 
#>   coord: cartesian
#>   mode:  static