Skip to contents

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

Usage

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

# S3 method for class 'mid.breakdown'
autoplot(object, ...)

Arguments

object

a "mid.breakdown" object to be visualized.

type

a character string specifying the type of the plot. One of "waterfall", "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 plot.

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 main layer.

Value

ggmid.mid.breakdown() returns a "ggplot" object.

Details

The S3 method of ggmid() for "mid.breakdown" objects creates a "ggplot" object that visualizes the breakdown of a single model prediction. The main layer is drawn using geom_col().

Examples

data(diamonds, package = "ggplot2")
set.seed(42)
idx <- sample(nrow(diamonds), 1e4)
mid <- interpret(price ~ (carat + cut + color + clarity)^2, diamonds[idx, ])
#> 'model' not passed: response variable in 'data' is used
mbd <- mid.breakdown(mid, diamonds[1L, ])
ggmid(mbd, type = "waterfall")

ggmid(mbd, type = "waterfall", theme = "midr")

ggmid(mbd, type = "barplot", theme = "Set 1")

ggmid(mbd, type = "dotchart", size = 3, theme = "Cividis")