plot_e2tree_vis: Interactive E2Tree Plot with visNetwork

View source: R/plot_e2tree_vis.R

plot_e2tree_visR Documentation

Interactive E2Tree Plot with visNetwork

Description

Displays an E2Tree as an interactive network plot using visNetwork. Features: drag nodes anywhere, zoom, pan, click for details. Starts with hierarchical layout, then you can freely move nodes.

Usage

plot_e2tree_vis(
  fit,
  data,
  ensemble,
  width = "100%",
  height = "100%",
  direction = "UD",
  node_spacing = 200,
  level_separation = 200,
  colors = NULL,
  show_percent = TRUE,
  show_prob = TRUE,
  show_n = TRUE,
  font_size = 14,
  edge_font_size = 12,
  split_label_style = "rpart",
  max_label_length = 50,
  details_on = "hover",
  navigation_buttons = FALSE,
  free_drag = FALSE
)

Arguments

fit

An e2tree object

data

The training data used to build the tree

ensemble

The ensemble model (randomForest or ranger)

width

Width of the widget (default: "100%")

height

Height of the widget (default: "100%")

direction

Layout direction: "UD" (top-down), "DU" (bottom-up), "LR" (left-right), "RL" (right-left)

node_spacing

Spacing between nodes at same level (default: 200)

level_separation

Spacing between levels (default: 200)

colors

Named vector of colors for classes, or NULL for auto

show_percent

Show percentage in nodes (default: TRUE)

show_prob

Show class probabilities in nodes (default: TRUE)

show_n

Show observation count in nodes (default: TRUE)

font_size

Font size for node labels (default: 14)

edge_font_size

Font size for edge labels (default: 12)

split_label_style

How to display split information:

  • "rpart" - Variable name in node, threshold on edges (like rpart.plot)

  • "full" - Full split rule on edges (variable + condition)

  • "threshold" - Only threshold values on edges (< 47, >= 47)

  • "yesno" - Simple yes/no on edges

  • "none" - No labels on edges (hover for details)

  • "innode" - Full split rule displayed IN the node (above stats)

max_label_length

Maximum characters for edge labels before truncating (default: 50)

details_on

When to show node details:

  • "hover" - Show on mouse hover (default, but may cover other nodes)

  • "click" - Show only on click (avoids covering highlighted nodes)

  • "none" - No tooltips (use for cleaner visualization)

navigation_buttons

Show navigation buttons (default: FALSE)

free_drag

If TRUE, nodes can be dragged in ALL directions (horizontal, vertical, diagonal). If FALSE (default), nodes can only be moved horizontally within their level.

Value

A visNetwork htmlwidget object

Examples


data(iris)
set.seed(42)
smp_size <- floor(0.75 * nrow(iris))
train_ind <- sample(seq_len(nrow(iris)), size = smp_size)
training <- iris[train_ind, ]

ensemble <- randomForest::randomForest(Species ~ ., data = training,
  importance = TRUE, proximity = TRUE)
D <- createDisMatrix(ensemble, data = training, label = "Species",
  parallel = list(active = FALSE, no_cores = 1))
setting <- list(impTotal = 0.1, maxDec = 0.01, n = 2, level = 5)
tree <- e2tree(Species ~ ., training, D, ensemble, setting)

# Basic usage
plot_e2tree_vis(tree, training, ensemble)



e2tree documentation built on May 15, 2026, 5:06 p.m.