Plot a LORT (Locally Optimal Recursive Tree) using ggplot2
Source:R/graphics_v3.R
plot_lort_tree.RdRenders a publication-quality CTA tree diagram for a single sub-tree within
a LORT object (indexed inspection), or a named list of plots for all sub-trees
(show_all = TRUE). Requires the ggplot2 package.
Usage
plot_lort_tree(
x,
index = 1L,
show_all = FALSE,
show_path = FALSE,
target_class = 1L,
color_by = c("none", "target_rate", "prediction"),
label_detail = c("simple", "full"),
show_node_ess = FALSE,
show_p = TRUE,
show_loo = TRUE,
main = NULL,
subtitle = NULL,
show_rule = TRUE,
show_metrics = FALSE,
short_edge_labels = TRUE,
node_text_size = 3.5,
edge_text_size = 3.2,
palette = NULL,
...
)Arguments
- x
A
cta_ortobject fromlort_fit.- index
Integer or character; which LORT node (sub-tree) to render. Default
1L(root sub-tree). Ignored whenshow_all = TRUE.- show_all
Logical; if
TRUE, return a named list of ggplot objects, one per LORT node, in node-id order. DefaultFALSE.- show_path
Logical; if
TRUE, delegates toplot_lort_pathto render the full path from root toindex. DefaultFALSE.- target_class
Integer; target class for endpoint coloring and target-rate annotation (default
1L).- color_by
Character; controls leaf-node fill color.
"none"(default): white fill;"target_rate": gradient;"prediction": discrete fill by predicted class.- label_detail
Character;
"simple"(default) or"full".- show_node_ess
Logical; append node-level ESS to split labels. Default
FALSE.- show_p
Logical; append
MC p = X.XXXto split-node labels. DefaultTRUE.- show_loo
Logical; append
LOO: STABLEorLOO p = X.XXXto split-node labels when LOO was active. DefaultTRUE.- main
Character; plot title. Default: auto-generated. When
show_all = TRUEeach plot's title includes the node id.- subtitle
Character; plot subtitle.
- show_rule
Logical; show branch condition labels on edges.
- show_metrics
Logical; append ESS/D to subtitle. Default
FALSE.- short_edge_labels
Logical; strip attribute-name prefix from edge labels. Default
TRUE.- node_text_size
Numeric; text size for node labels. Default
3.5.- edge_text_size
Numeric; text size for edge labels. Default
3.2.- palette
Named list for color overrides.
NULLuses defaults.- ...
Additional arguments passed to
plot_lort_pathwhenshow_path = TRUE; otherwise ignored.
Value
A ggplot object, or (when show_all =
TRUE) a named list of ggplot objects.
Examples
# \donttest{
if (requireNamespace("ggplot2", quietly = TRUE)) {
X <- data.frame(
A = c(rep(0L,20), rep(1L,20), rep(1L,20)),
B = c(rep(0L,20), rep(0L,20), rep(1L,20))
)
y <- c(rep(0L,40), rep(1L,20))
lort <- lort_fit(X, y, mc_iter=100L, mc_seed=42L, loo="off", min_n=5L)
p <- plot_lort_tree(lort, index=1L)
print(p)
}
# }