Learn R Programming

flashlight (version 0.3.0)

plot.light_effects: Visualize Multiple Types of Profiles Together

Description

Visualizes response-, prediction-, partial dependence, and/or ALE profiles of a (multi-)flashlight with respect to a covariable v. Different flashlights or a single flashlight with one "by" variable are separated by a facet wrap.

Usage

# S3 method for light_effects
plot(x, use = c("response", "predicted", "pd"),
  zero_counts = TRUE, size_factor = 1, facet_scales = "free_x",
  facet_nrow = 1L, rotate_x = TRUE, ...)

Arguments

x

An object of class light_effects.

use

A vector of elements to show. Any subset of ("response", "predicted", "pd" and "ale") or "all". Defaults to all except "ale"

zero_counts

Logical flag if 0 count levels should be shown on the x axis.

size_factor

Factor used to enlarge default size in geom_point and geom_line.

facet_scales

Scales argument passed to facet_wrap.

facet_nrow

Number of rows in facet_wrap. Must be 1 if plot_counts should be used.

rotate_x

Should x axis labels be rotated by 45 degrees?

...

Further arguments passed to geoms.

Value

An object of class ggplot2.

See Also

light_effects, plot_counts.

Examples

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

plot(light_effects(mod_full, v = "Species"))
x <- light_effects(mod_full, v = "Petal.Width")
plot(x)
plot(x, use = "response")
plot(x, use = c("pd", "ale"))
plot_counts(plot(x, use = c("pd", "ale")), x)

x <- light_effects(mod_full, v = "Petal.Width", stats = "quartiles")
plot(x)
plot_counts(plot(x, use = "response"), x, alpha = 0.2)

x <- light_effects(mod_full, v = "Petal.Width", by = "Species")
plot(x)
p <- plot(x, zero_counts = FALSE, use = "all")
plot_counts(p, x, alpha = 0.2)

plot(light_effects(mod_full, v = "Petal.Width", by = "Species",
  stats = "quartiles"))
plot(light_effects(mods, v = "Petal.Width", stats = "quartiles"))
# }

Run the code above in your browser using DataLab