Plots the response curves of models fitted with rf(), rf_repeat(), or rf_spatial().

  model = NULL,
  variables = NULL,
  quantiles = c(0.1, 0.5, 0.9),
  grid.resolution = 200,
  line.color = viridis::viridis(length(quantiles), option = "F", end = 0.9),
  ncol = 2, = FALSE,
  verbose = TRUE



A model fitted with rf(), rf_repeat(), or rf_spatial().


Character vector, names of predictors to plot. If NULL, the most important variables (importance higher than the median) in x are selected. Default: NULL.


Numeric vector with values between 0 and 1, argument probs of quantile. Quantiles to set the other variables to. Default: c(0.1, 0.5, 0.9)


Integer between 20 and 500. Resolution of the plotted curve Default: 100


Character vector with colors, or function to generate colors for the lines representing quantiles. Must have the same number of colors as quantiles are defined. Default: viridis::viridis(length(quantiles), option = "F", end = 0.9)


Integer, argument of wrap_plots. Defaults to the rounded squared root of the number of plots. Default: 2

Logical, if TRUE, the observed data is plotted along with the response curves. Default: FALSE


Logical, if TRUE the plot is printed. Default: TRUE


A list with slots named after the selected variables, with one ggplot each.


All variables that are not plotted in a particular response curve are set to the values of their respective quantiles, and the response curve for each one of these quantiles is shown in the plot. When the input model was fitted with rf_repeat() with keep.models = TRUE, then the plot shows the median of all model runs, and each model run separately as a thinner line. The output list can be plotted all at once with patchwork::wrap_plots(p) or cowplot::plot_grid(plotlist = p), or one by one by extracting each plot from the list.



#loading example data

#fitting a random forest model
m <- rf(
 data = plant_richness_df, = "richness_species_vascular",
 predictor.variable.names = colnames(plant_richness_df)[5:21],
 n.cores = 1,
 verbose = FALSE

#response curves of most important predictors
plot_response_curves(model = m)