View source: R/plot_e2tree_vis.R
| plot_e2tree_vis | R Documentation |
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.
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
)
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:
|
max_label_length |
Maximum characters for edge labels before truncating (default: 50) |
details_on |
When to show node details:
|
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. |
A visNetwork htmlwidget object
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.