Create a compact edge-panel generator for tree plots
Source:R/tree_default_name.R
tree_edge_panel_compact.RdBuilds a partykit graph-content generator that draws compact edge labels
using tree_compact_split_label(). This is useful when factor splits have
many levels or when tree plots need shorter, more readable split labels.
Usage
tree_edge_panel_compact(
obj,
var_labels = NULL,
digits = 3,
fill = "white",
justmin = 4,
just = c("alternate", "increasing", "decreasing", "equal"),
max_items = 3L,
max_chars = 24L,
plural_overrides = NULL
)Arguments
- obj
A fitted tree object inheriting from
party.- var_labels
An optional named character vector of display labels.
- digits
Number of digits to use when formatting numeric split labels.
- fill
Fill color used behind edge labels.
- justmin
Minimum average label width before alternating justification is used.
- just
One of
"alternate","increasing","decreasing", or"equal"controlling vertical placement of sibling edge labels.- max_items
Maximum number of comma-separated items to show before shortening the label.
- max_chars
Maximum wrapping width used for unshortened labels.
- plural_overrides
An optional named character vector giving custom plural nouns for summarized level groups.
Value
A graph-content generator function suitable for the edge_panel
argument of partykit::plot.party().
Examples
data(kenya, package = "ineqTrees")
kenya_plot_vars <- c("wealth", "deadu5_num", "rural", "ed", "reg", "unskilled")
kenya_plot_data <- kenya[
stats::complete.cases(kenya[, kenya_plot_vars]),
kenya_plot_vars
]
set.seed(20260512)
kenya_plot_data <- kenya_plot_data[
sample.int(nrow(kenya_plot_data), 800L),
,
drop = FALSE
]
kenya_plot_fit <- ci_tree(
cbind(wealth, deadu5_num) ~ rural + ed + reg + unskilled,
data = kenya_plot_data,
rank_name = "wealth",
outcome_name = "deadu5_num",
control = ci_tree_control(
minsplit = 100,
minbucket = 50,
minprob = 0.05,
maxdepth = 3
)
)
kenya_var_labels <- c(
rural = "Residence",
ed = "Mother education",
reg = "Province",
unskilled = "Mother occupation"
)
inherits(tree_edge_panel_compact, "grapcon_generator")
#> [1] TRUE
is.function(tree_edge_panel_compact(
kenya_plot_fit,
var_labels = kenya_var_labels,
plural_overrides = c(Province = "provinces")
))
#> [1] TRUE