plot.light_breakdown: Visualize Variable Contribution Breakdown for Single...

View source: R/plot_light_breakdown.R

plot.light_breakdownR Documentation

Visualize Variable Contribution Breakdown for Single Observation

Description

Minimal visualization of an object of class "light_breakdown" as waterfall plot. The object returned is of class "ggplot" and can be further customized.

Usage

## S3 method for class 'light_breakdown'
plot(x, facet_scales = "free", facet_ncol = 1, rotate_x = FALSE, ...)

Arguments

x

An object of class "light_breakdown".

facet_scales

Scales argument passed to ggplot2::facet_wrap().

facet_ncol

ncol argument passed to ggplot2::facet_wrap().

rotate_x

Should x axis labels be rotated by 45 degrees?

...

Further arguments passed to ggplot2::geom_label().

Details

The waterfall plot is to be read from top to bottom. The first line describes the (weighted) average prediction in the query data used to start with. Then, each additional line shows how the prediction changes due to the impact of the corresponding variable. The last line finally shows the original prediction of the selected observation. Multiple flashlights are shown in different facets. Positive and negative impacts are visualized with different colors.

Value

An object of class "ggplot".

See Also

light_breakdown()

Examples

fit <- lm(Sepal.Length ~ . + Petal.Length:Species, data = iris)
fl <- flashlight(model = fit, label = "lm", data = iris, y = "Sepal.Length")
plot(light_breakdown(fl, new_obs = iris[1, ]))

flashlight documentation built on May 31, 2023, 6:19 p.m.