View source: R/ggmid_mid_breakdown.R
ggmid.mid.breakdown | R Documentation |
For "mid.breakdown" objects, ggmid()
visualizes the breakdown of a prediction by component functions.
## S3 method for class 'mid.breakdown'
ggmid(
object,
type = c("waterfall", "barplot", "dotchart"),
theme = NULL,
terms = NULL,
max.nterms = 15L,
width = NULL,
vline = TRUE,
catchall = "others",
format = c("%t=%v", "%t"),
...
)
## S3 method for class 'mid.breakdown'
autoplot(object, ...)
object |
a "mid.breakdown" object to be visualized. |
type |
the plotting style. One of "waterfall", "barplot" or "dotchart". |
theme |
a character string or object defining the color theme. See |
terms |
an optional character vector specifying which terms to display. |
max.nterms |
the maximum number of terms to display in the plot. Less important terms will be grouped into a "catchall" category. |
width |
a numeric value specifying the width of the bars. |
vline |
logical. If |
catchall |
a character string for the catchall label. |
format |
a character string or character vector of length two to be used as the format of the axis labels. Use "%t" for the term name (e.g., "Wind") and "%v" for the values (e.g., "30"). |
... |
optional parameters passed on to the main layer. |
This is an S3 method for the ggmid()
generic that creates a breakdown plot from a "mid.breakdown" object, visualizing the contribution of each component function to a single prediction.
The type
argument controls the visualization style.
The default, type = "waterfall"
(default), creates a waterfall plot that shows how the prediction is built up from the intercept, with each term's contribution sequentially added or subtracted.
The type = "barplot"
option creates a standard bar plot where the length of each bar represents the magnitude of the term's contribution.
The type = "dotchart"
option creates a dot plot showing the contribution of each term as a point connected to a zero baseline.
ggmid.mid.breakdown()
returns a "ggplot" object.
mid.breakdown
, ggmid
, plot.mid.breakdown
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, ])
# Create a waterfall plot
ggmid(mbd, type = "waterfall")
# Create a bar plot with a different theme
ggmid(mbd, type = "barplot", theme = "highlight")
# Create a dot chart
ggmid(mbd, type = "dotchart", size = 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.