Learn R Programming

flashlight (version 0.3.0)

plot.light_profile: Visualize Profiles, e.g. of Partial Dependence

Description

Minimal visualization of an object of class light_profile. The object returned is of class ggplot and can be further customized.

Usage

# S3 method for light_profile
plot(x, swap_dim = FALSE,
  facet_scales = "free_x", rotate_x = x$type != "partial dependence",
  ...)

Arguments

x

An object of class light_profile.

swap_dim

If multiflashlight and one "by" variable or single flashlight with two "by" variables, swap the role of dodge/fill variable and facet variable. If multiflashlight or one "by" variable, use facets instead of colors.

facet_scales

Scales argument passed to facet_wrap.

rotate_x

Should x axis labels be rotated by 45 degrees? TRUE, except for type "partial dependence".

...

Further arguments passed to geom_point and geom_line.

Value

An object of class ggplot2.

Details

Either lines and points are plotted (if stats = "mean") or quartile boxes. If there is a "by" variable or a multiflashlight, this first dimension is taken care by color (or if swap_dim = TRUE by facets). If there are two "by" variables or a multiflashlight with one "by" variable, the first "by" variable is visualized as color, the second one or the multiflashlight via facet (change with swap_dim).

See Also

light_profile, plot.light_effects.

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(light_profile(mod_full, v = "Species"))
plot(light_profile(mod_full, v = "Species", type = "ale"))
plot(light_profile(mod_full, v = "Species", type = "response"))
plot(light_profile(mod_full, v = "Species", type = "residual", stats = "quartiles"))

plot(light_profile(mod_full, v = "Petal.Width"))
plot(light_profile(mod_full, v = "Petal.Width", type = "residual"))
plot(light_profile(mod_full, v = "Petal.Width", stats = "quartiles"))

plot(light_profile(mod_full, v = "Petal.Width", by = "Species"))
plot(light_profile(mod_full, v = "Petal.Width", by = "Species"), swap_dim = TRUE)

plot(light_profile(mods, v = "Species"))
plot(light_profile(mods, v = "Petal.Width"))
plot(light_profile(mods, v = "Petal.Width"), swap_dim = TRUE)
plot(light_profile(mods, v = "Petal.Width", by = "Species"))
plot(light_profile(mods, v = "Petal.Width", by = "Species", type = "ale"))
plot(light_profile(mods, v = "Petal.Width", by = "Species"), swap_dim = TRUE)
plot(light_profile(mods, v = "Petal.Width", by = "Species", type = "predicted"))
plot(light_profile(mods, v = "Petal.Width", by = "Species",
  type = "predicted", n_bins = 5), swap_dim = TRUE)
plot(light_profile(mods, v = "Petal.Width", by = "Species",
  type = "predicted", stats = "quartiles"), rotate_x = TRUE)
# }

Run the code above in your browser using DataLab