autoplot.partial | R Documentation |
Plots partial dependence functions (i.e., marginal effects) using
ggplot2
graphics.
## S3 method for class 'partial' autoplot( object, center = FALSE, plot.pdp = TRUE, pdp.color = "red", pdp.size = 1, pdp.linetype = 1, rug = FALSE, smooth = FALSE, smooth.method = "auto", smooth.formula = y ~ x, smooth.span = 0.75, smooth.method.args = list(), contour = FALSE, contour.color = "white", train = NULL, xlab = NULL, ylab = NULL, main = NULL, legend.title = "yhat", ... ) ## S3 method for class 'ice' autoplot( object, center = FALSE, plot.pdp = TRUE, pdp.color = "red", pdp.size = 1, pdp.linetype = 1, rug = FALSE, train = NULL, xlab = NULL, ylab = NULL, main = NULL, ... ) ## S3 method for class 'cice' autoplot( object, plot.pdp = TRUE, pdp.color = "red", pdp.size = 1, pdp.linetype = 1, rug = FALSE, train = NULL, xlab = NULL, ylab = NULL, main = NULL, ... )
object |
An object that inherits from the |
center |
Logical indicating whether or not to produce centered ICE
curves (c-ICE curves). Only useful when |
plot.pdp |
Logical indicating whether or not to plot the partial
dependence function on top of the ICE curves. Default is |
pdp.color |
Character string specifying the color to use for the partial
dependence function when |
pdp.size |
Positive number specifying the line width to use for the
partial dependence function when |
pdp.linetype |
Positive number specifying the line type to use for the
partial dependence function when |
rug |
Logical indicating whether or not to include rug marks on the
predictor axes. Default is |
smooth |
Logical indicating whether or not to overlay a LOESS smooth.
Default is |
smooth.method |
Character string specifying the smoothing method
(function) to use (e.g., |
smooth.formula |
Formula to use in smoothing function (e.g.,
|
smooth.span |
Controls the amount of smoothing for the default loess
smoother. Smaller numbers produce wigglier lines, larger numbers produce
smoother lines. Default is |
smooth.method.args |
List containing additional arguments to be passed
on to the modeling function defined by |
contour |
Logical indicating whether or not to add contour lines to the level plot. |
contour.color |
Character string specifying the color to use for the
contour lines when |
train |
Data frame containing the original training data. Only required
if |
xlab |
Character string specifying the text for the x-axis label. |
ylab |
Character string specifying the text for the y-axis label. |
main |
Character string specifying the text for the main title of the plot. |
legend.title |
Character string specifying the text for the legend title.
Default is |
... |
Additional (optional) arguments to be passed onto
|
A "ggplot"
object.
## Not run: # # Regression example (requires randomForest package to run) # # Load required packages library(ggplot2) # for autoplot() generic library(gridExtra) # for `grid.arrange()` library(magrittr) # for forward pipe operator `%>%` library(randomForest) # Fit a random forest to the Boston housing data data (boston) # load the boston housing data set.seed(101) # for reproducibility boston.rf <- randomForest(cmedv ~ ., data = boston) # Partial dependence of cmedv on lstat boston.rf %>% partial(pred.var = "lstat") %>% autoplot(rug = TRUE, train = boston) + theme_bw() # Partial dependence of cmedv on lstat and rm boston.rf %>% partial(pred.var = c("lstat", "rm"), chull = TRUE, progress = TRUE) %>% autoplot(contour = TRUE, legend.title = "cmedv", option = "B", direction = -1) + theme_bw() # ICE curves and c-ICE curves age.ice <- partial(boston.rf, pred.var = "lstat", ice = TRUE) grid.arrange( autoplot(age.ice, alpha = 0.1), # ICE curves autoplot(age.ice, center = TRUE, alpha = 0.1), # c-ICE curves ncol = 2 ) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.