Learn R Programming

midr (version 0.5.0)

plot.mid.breakdown: Plot MID Breakdown with graphics Package

Description

For "mid.breakdown" objects, plot() visualizes the breakdown of a prediction by component functions.

Usage

# S3 method for mid.breakdown
plot(
  x,
  type = c("waterfall", "barplot", "dotchart"),
  theme = NULL,
  terms = NULL,
  max.bars = 15L,
  width = NULL,
  vline = TRUE,
  catchall = "others",
  format = c("%t=%v", "%t"),
  ...
)

Value

plot.mid.breakdown() produces a plot and returns NULL.

Arguments

x

a "mid.breakdown" object to be visualized.

type

a character string specifying the type of the plot. One of "barplot" or "dotchart".

theme

a character string specifying the color theme or any item that can be used to define "color.theme" object.

terms

an optional character vector specifying the terms to be displayed.

max.bars

an integer specifying the maximum number of bars in the barplot, boxplot and dotchart.

width

a numeric value specifying the width of the bars.

vline

logical. If TRUE, the vertical line is drawn at zero or the intercept.

catchall

a character string to be used as the catchall label.

format

a character string or character vector of length two to be used as the format of the axis labels. "t" and "v" immediately after the percent sign are replaced with the corresponding term and value.

...

optional parameters to be passed to the graphing function. Possible arguments are "col", "fill", "pch", "cex", "lty", "lwd" and aliases of them.

Details

The S3 method of plot() for "mid.breakdown" objects creates a visualization of the MID breakdown using the functions of the graphics package.

Examples

Run this code
data(diamonds, package = "ggplot2")
set.seed(42)
idx <- sample(nrow(diamonds), 1e4)
mid <- interpret(price ~ (carat + cut + color + clarity)^2, diamonds[idx, ])
mbd <- mid.breakdown(mid, diamonds[1L, ])
plot(mbd, type = "waterfall")
plot(mbd, type = "waterfall", theme = "midr")
plot(mbd, type = "barplot", theme = "Set 1")
plot(mbd, type = "dotchart", theme = "Cividis")

Run the code above in your browser using DataLab