Learn R Programming

ggRandomForests: Visually Exploring Random Forests

ggRandomForests provides ggplot2-based diagnostic and exploration plots for random forests fit with randomForestSRC (>= 3.4.0) or randomForest. It keeps the data step apart from the figure step, so you can inspect, save, or reuse the tidy object on its own. Listed in the ggplot2 extensions gallery.

Installation

# CRAN (stable)
install.packages("ggRandomForests")

# Development version from GitHub
# install.packages("remotes")
remotes::install_github("ehrlinger/ggRandomForests")

Quick start

library(randomForestSRC)
library(ggRandomForests)

# 1. Fit a forest (regression)
rf <- rfsrc(medv ~ ., data = MASS::Boston, importance = TRUE)

# 2. Check convergence: did the forest grow enough trees?
plot(gg_error(rf))

# 3. Rank predictors by importance
plot(gg_vimp(rf))

# 4. Marginal dependence for top variables
gg_v <- gg_variable(rf)
plot(gg_v, xvar = "lstat")
plot(gg_v, xvar = rf$xvar.names, panel = TRUE, se = FALSE)

# 5. Partial dependence for a single predictor
pv <- plot.variable(rf, xvar.names = "lstat", partial = TRUE, show.plots = FALSE)
pd <- gg_partial(pv)
plot(pd)

For survival forests, see the package vignette:

vignette("ggRandomForests")

For variable importance with varPro — partial dependence, importance z-scores, beta importance, individual/local importance, and isolation forests — see the dedicated vignette:

vignette("varpro", package = "ggRandomForests")

The unsupervised varPro tools — gg_udependent(), gg_beta_uvarpro(), and gg_sdependent(), which read structure off a uvarpro() fit with no outcome — have their own short vignette:

vignette("uvarpro", package = "ggRandomForests")

Function reference

FunctionInputWhat you get
gg_error()rfsrc / randomForestOOB error vs. number of trees
gg_vimp()rfsrc / randomForestVariable importance ranking
gg_rfsrc()rfsrc / randomForestPredicted vs. observed values
gg_variable()rfsrc / randomForestMarginal dependence data frame
gg_partial()plot.variable outputPartial dependence (continuous + categorical)
gg_partial_rfsrc()rfsrc modelPartial dependence via partial.rfsrc
gg_survival()rfsrc survival forestKaplan–Meier / Nelson–Aalen estimates
gg_roc()rfsrc / randomForest (class)ROC curve data
gg_brier()rfsrc (survival)Time-resolved Brier score and CRPS

Each gg_* function has a matching plot() S3 method that hands back a single plottable object: a ggplot you extend with +, or a patchwork composite for the multi-panel methods. Every gg_* object also has print() and summary() methods: print() shows a short header at the REPL rather than dumping every row (use head() when you want the rows), and summary() gives you a diagnostics object you can print or keep.

Why ggRandomForests?

The package is built on one decision: keep the data step and the figure step apart. The gg_* functions pull a tidy data object out of the forest; the plot() methods turn that object into a ggplot2 figure. Two things follow from that split.

First, the data object stands on its own. It carries everything its plot needs, so you can save it, inspect it, or come back to it later without keeping the original forest — which can be large — in memory.

Second, you are never locked into the default figure. Because a plot() method returns a single plottable object (a ggplot, or a patchwork composite for the multi-panel methods), you can add layers, swap scales, or apply a theme; and if the default is not what you want, you can ignore it entirely and build the figure from the tidy data yourself.

Recent changes

See NEWS.md for the full changelog. Recent highlights:

  • v3.4.0 Unsupervised varPro wrappers (gg_beta_uvarpro(), gg_sdependent()) with their own vignette; gg_partial_rfsrc() now handles factor predictors correctly.
  • v3.3.0 varPro partial plots default to interpretable scales — probability for classification, survival S(τ) for survival.
  • v3.1.0 varPro integration: release-rule importance, partial dependence, local importance, anomaly scores, and the dependency graph.

References

Breiman, L. (2001). Random forests, Machine Learning, 45:5–32.

Ishwaran H. and Kogalur U.B. randomForestSRC: Random Forests for Survival, Regression and Classification. R package version >= 3.4.0. https://cran.r-project.org/package=randomForestSRC

Ishwaran H. and Kogalur U.B. (2007). Random survival forests for R. R News 7(2), 25–31.

Ishwaran H., Kogalur U.B., Blackstone E.H. and Lauer M.S. (2008). Random survival forests. Ann. Appl. Statist. 2(3), 841–860.

Liaw A. and Wiener M. (2002). Classification and Regression by randomForest. R News 2(3), 18–22.

Wickham H. (2009). ggplot2: Elegant Graphics for Data Analysis. Springer New York.

Copy Link

Version

Install

install.packages('ggRandomForests')

Monthly Downloads

700

Version

3.5.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

John Ehrlinger

Last Published

August 4th, 2026

Functions in ggRandomForests (3.5.0)

gg_error

Random forest error trajectory data object
gg_partial_varpro

Partial dependence data from a varPro model
gg_roc.rfsrc

ROC (Receiver Operating Characteristic) curve data from a classification forest.
gg_brier

Brier score and CRPS for survival forests
gg_isopro

Tidy data from a varPro isolation-forest fit
gg_partial

Split partial dependence data into continuous or categorical datasets
gg_sdependent

Signal-variable detection from an unsupervised varPro fit
gg_rfsrc.rfsrc

Predicted response data object
gg_partial_rfsrc

Partial dependence data from an rfsrc model
gg_ivarpro

Individual (local) variable importance from a varPro fit
gg_shap

SHAP (Shapley additive explanations) data object
gg_varpro

Variable importance data from a varPro model
plot.gg_beta_uvarpro

Plot a gg_beta_uvarpro object
ggrandomforests.news

Display the ggRandomForests NEWS file
nelson

nonparametric Nelson-Aalen estimates
gg_udependent

Variable dependency graph from a uvarpro model
gg_survival

Nonparametric survival estimates.
gg_vimp

Variable Importance (VIMP) data object
kaplan

nonparametric Kaplan-Meier estimates
gg_variable

Marginal variable dependence data object.
plot.gg_partial

Plot a gg_partial object
plot.gg_partial_varpro

Plot a gg_partial_varpro object
plot.gg_partial_rfsrc

Plot a gg_partial_rfsrc object
plot.gg_ivarpro

Plot a gg_ivarpro object
plot.gg_brier

Plot a gg_brier object
plot.gg_rfsrc

Predicted response plot from a gg_rfsrc object.
plot.gg_error

Plot a gg_error object
plot.gg_roc

ROC plot generic function for a gg_roc object.
plot.gg_beta_varpro

Plot a gg_beta_varpro object
plot.gg_isopro

Plot a varPro isolation-forest anomaly score
plot.gg_sdependent

Plot a gg_sdependent object
plot.gg_survival

Plot a gg_survival object.
plot.gg_vimp

Plot a gg_vimp object, extracted variable importance of a rfsrc object
plot.gg_variable

Plot a gg_variable object,
print.gg_beta_uvarpro

Print methods for gg_* data objects
plot.gg_udependent

Plot a gg_udependent variable dependency graph
quantile_pts

Quantile-based cut points for coplots
plot.gg_varpro

Plot a gg_varpro variable importance object
shap_beeswarm

SHAP beeswarm summary plot
plot.gg_shap

Plot a gg_shap object
shap_dependence

SHAP dependence plot
shap_importance

SHAP global importance bar chart
surv_partial.rfsrc

Survival partial dependence data for one or more predictors
varpro_feature_names

Recover original variable names from varpro one-hot encoded feature names
summary.gg_beta_uvarpro

Summary methods for gg_* data objects
bootstrap_survival

Bootstrap pointwise confidence bands for a mean survival curve
gg_beta_varpro

Per-variable lasso-beta importance from a varPro fit
calc_auc

Area Under the ROC Curve calculator
ggRandomForests-package

ggRandomForests: Visually Exploring Random Forests
calc_roc.rfsrc

Receiver Operator Characteristic calculator
autoplot.gg

autoplot methods for ggRandomForests data objects
gg_beta_uvarpro

Per-variable lasso-beta importance from an unsupervised varPro fit
.build_varpro_imp_tree

Build per-tree importance matrix from varpro object results
.build_varpro_imp_dfs

Build the tidy importance data structures from importance() output
.varpro_imp_stats

Compute per-variable box statistics from a per-tree importance matrix