Skip to contents

Renders 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_ort object from lort_fit.

index

Integer or character; which LORT node (sub-tree) to render. Default 1L (root sub-tree). Ignored when show_all = TRUE.

show_all

Logical; if TRUE, return a named list of ggplot objects, one per LORT node, in node-id order. Default FALSE.

show_path

Logical; if TRUE, delegates to plot_lort_path to render the full path from root to index. Default FALSE.

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.XXX to split-node labels. Default TRUE.

show_loo

Logical; append LOO: STABLE or LOO p = X.XXX to split-node labels when LOO was active. Default TRUE.

main

Character; plot title. Default: auto-generated. When show_all = TRUE each 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. NULL uses defaults.

...

Additional arguments passed to plot_lort_path when show_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)
}

# }