Skip to content

gg_variable() returns an empty plot for randomForest objects (classification & regression) #80

@ehrlinger

Description

@ehrlinger

Summary

plot(gg_variable(rf)) for a randomForest object renders an empty figure (zero ggplot layer rows) — for both classification and regression. The rfsrc path works; the randomForest path does not. Surfaced while validating the randomForest engine (historically less exercised than rfsrc).

Reproduction

library(ggRandomForests); library(randomForest); library(ggplot2)
set.seed(42)

rf_c <- randomForest(Species ~ ., data = iris, importance = TRUE)
nrow(layer_data(plot(gg_variable(rf_c))))   # => 0  (expected: > 0)

rf_r <- randomForest(mpg ~ ., data = mtcars, importance = TRUE)
nrow(layer_data(plot(gg_variable(rf_r))))   # => 0  (expected: > 0)

Expected vs actual

  • Expected: a populated variable-dependence plot (points/curves), as with the rfsrc path.
  • Actual: plot() returns a ggplot with 0 layer rows — nothing is drawn.

Notes / suspected area

  • gg_variable.randomForest likely recovers the training frame / response differently than the plot method expects (cf. the .rf_recover_model_frame() machinery referenced in NEWS v2.7.0); the resulting tidy frame appears to have no plottable rows or a column-name mismatch.
  • The existing empty-figure regression suite (tests/testthat/test_plot_layer_data.R) does not cover the randomForest gg_variable path — hence undetected.

Scope

Part of a broader randomForest engine validation pass (see sibling issue for gg_roc). Fix should also extend test_plot_layer_data.R with a randomForest plot matrix so this class of bug is permanently guarded. Not blocking the v2.8.0 varPro work; candidate for the v2.8 cycle as a bug fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions