Learn R Programming

flashlight (version 0.3.0)

plot.light_breakdown: 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 light_breakdown
plot(x, facet_scales = "free",
  facet_ncol = 1, ...)

Arguments

x

An object of class light_breakdown.

facet_scales

Scales argument passed to facet_wrap.

facet_ncol

ncol argument passed to facet_wrap.

...

Further arguments passed to geom_label.

Value

An object of class ggplot2.

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.

See Also

light_importance.

Examples

Run this code
# NOT RUN {
fit_full <- lm(Sepal.Length ~ ., data = iris)
fit_part <- lm(Sepal.Length ~ Petal.Length, data = iris)
mod_full <- flashlight(model = fit_full, label = "full", data = iris, y = "Sepal.Length")
mod_part <- flashlight(model = fit_part, label = "part", data = iris, y = "Sepal.Length")
mods <- multiflashlight(list(mod_full, mod_part))

plot(x <- light_breakdown(mod_full, new_obs = iris[1, ]))
plot(light_breakdown(mods, new_obs = iris[1, ]), size = 2.5)
plot(light_breakdown(mods, new_obs = iris[1, ]), facet_ncol = 2)
# }

Run the code above in your browser using DataLab