Plotting of ice objects.
Usage
# S3 method for class 'ice'
plot(
x,
plot_margin = 0.05,
frac_to_plot = 1,
plot_points_indices = NULL,
plot_orig_pts_preds = TRUE,
pts_preds_size = 1.5,
colorvec,
color_by = NULL,
x_quantile = TRUE,
plot_pdp = TRUE,
centered = FALSE,
prop_range_y = TRUE,
rug_quantile = seq(from = 0, to = 1, by = 0.1),
centered_percentile = 0,
point_labels = NULL,
point_labels_size = NULL,
prop_type = "sd",
verbose = TRUE,
num_cores = 1,
...
)Arguments
- x
Object of class
iceto plot.- plot_margin
Extra margin to pass to
ylimas a fraction of the range ofx$ice_curves.- frac_to_plot
If
frac_to_plotis less than 1, randomly plotfrac_to_plotfraction of the curves inx$ice_curves.- plot_points_indices
If not
NULL, this plots only the indices of interest. If notNULL,frac_to_plotmust be 1 otherwise an error is thrown. Default isNULL.- plot_orig_pts_preds
If
TRUE, marks each curve at the location of the observation's actual fitted value. IfFALSE, no mark is drawn.- pts_preds_size
Size of points to make if
plot_origin_pts_predsisTRUE.- colorvec
Optional vector of colors to use for each curve.
- color_by
Optional variable name in
Xice, column number inXice, or data vector of the correct length to color curves by. If thecolor_byvariable has 10 or fewer unique values, a discrete set of colors is used for each value and a legend is printed and returned. If there are more values, curves are colored from light to dark corresponding to low to high values of the variable specified bycolor_by.- x_quantile
If
TRUE, the plot is drawn with the x-axis taken to bequantile(gridpts). IfFALSE, the predictor's original scale is used.- plot_pdp
If
TRUE, the PDP is plotted and highlighted in yellow.- centered
If
TRUE, all curves are re-centered to be 0 at the quantile given bycentered_percentile. See Goldstein et al (2013) for details and examples. IfFALSE, the originalice_curvesare plotted.- prop_range_y
When
TRUEandcentered=TRUEas well, the range of the right vertical axis displays the centered values as a fraction of the sd of the fitted values on actual observations ifprop_typeis missing or set to"sd". Ifprop_typeis set to"range", the right axis displays the centered values as a fraction of the range of the fitted values over the actual observations.- rug_quantile
If not
NULL, tick marks are drawn on the x-axis corresponding to the vector of quantiles specified by this parameter. Forced toNULLwhenx_quantileis set toTRUE.- centered_percentile
The percentile of
predictorfor which allice_curvesare "pinched together" and set to be 0. Default is 0.- point_labels
If not
NULL, labels to plot next to each point. Default isNULL.- point_labels_size
If not
NULL, size of labels to plot next to each point. Default isNULLwhich means it's the size ofpts_preds_size.- prop_type
Scaling factor for the right vertical axis in centered plots if
prop_range_yisTRUE. Can be one of"sd"(default) or"range". Ignored ifcenteredandprop_range_yare not bothTRUE.- verbose
If
TRUE, prints the color legend to the console.- num_cores
Used for parallel plotting speedup. Default is 1.
- ...
Other arguments to be passed to the
plotfunction.
Value
A list with the following elements.
- plot_points_indices
Row numbers of
Xiceof those observations presented in the plot.- legend_text
If the
color_byargument was used, a legend describing the map between thecolor_bypredictor and curve colors.
Examples
if (FALSE) { # \dontrun{
require(ICEbox)
require(randomForest)
require(MASS) #has Boston Housing data, Pima
data(Boston) #Boston Housing data
X = Boston
y = X$medv
X$medv = NULL
## build a RF:
bhd_rf_mod = randomForest(X, y)
## Create an 'ice' object for the predictor "age":
bhd.ice = ice(object = bhd_rf_mod, X = X, y = y, predictor = "age",
frac_to_build = .1)
## plot
plot(bhd.ice, x_quantile = TRUE, plot_pdp = TRUE, frac_to_plot = 1)
## centered plot
plot(bhd.ice, x_quantile = TRUE, plot_pdp = TRUE, frac_to_plot = 1,
centered = TRUE)
## color the curves by high and low values of 'rm'.
# First create an indicator variable which is 1 if the number of
# rooms is greater than the median:
median_rm = median(X$rm)
bhd.ice$Xice$I_rm = ifelse(bhd.ice$Xice$rm > median_rm, 1, 0)
plot(bhd.ice, frac_to_plot = 1, centered = TRUE, prop_range_y = TRUE,
x_quantile = T, plot_orig_pts_preds = T, color_by = "I_rm")
bhd.ice = ice(object = bhd_rf_mod, X = X, y = y, predictor = "age",
frac_to_build = 1)
plot(bhd.ice, frac_to_plot = 1, centered = TRUE, prop_range_y = TRUE,
x_quantile = T, plot_orig_pts_preds = T, color_by = y)
} # }