Build a compact display label for a tree split
Source:R/tree_default_name.R
tree_compact_split_label.RdFormats split labels for use on tree edges. Short labels are wrapped with the variable name, while long comma-separated level lists can be shortened to a compact summary showing the number of grouped levels and the first few items.
Usage
tree_compact_split_label(
var_name,
label,
var_labels = NULL,
max_items = 3L,
max_chars = 24L,
plural_overrides = NULL
)Arguments
- var_name
A character scalar naming the split variable.
- label
A character scalar containing the split label to display.
- var_labels
An optional named character vector of display 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.
Examples
tree_compact_split_label("wealth_index", "lowest")
#> [1] "wealth index\nlowest"
tree_compact_split_label(
"water_source",
"piped, borehole, well, river",
var_labels = c(water_source = "Water source"),
plural_overrides = c("Water source" = "sources")
)
#> [1] "Water source\n4 sources\npiped, borehole, well, ..."