Skip to contents

Formats 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.

Value

A length-one character vector suitable for edge labels in tree plots.

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, ..."