Learn R Programming

cograph (version 2.0.0)

abbrev_label: Abbreviate Labels

Description

Abbreviates labels to a maximum length, adding ellipsis if truncated.

Usage

abbrev_label(label, abbrev = NULL, n_labels = NULL)

label_abbrev(label, abbrev = NULL, n_labels = NULL)

Value

Character vector of (possibly abbreviated) labels.

Arguments

label

Character vector of labels to abbreviate.

abbrev

Abbreviation control:

  • NULL: No abbreviation (return labels unchanged)

  • Integer: Maximum character length (truncate + ellipsis)

  • "auto": Adaptive abbreviation based on label count

n_labels

Number of labels (used for "auto" mode). If NULL, uses length(label).

Examples

Run this code
labels <- c("VeryLongStateName", "Short", "AnotherLongName")

# No abbreviation
abbrev_label(labels, NULL)

# Fixed max length
abbrev_label(labels, 5)  # "Very...", "Short", "Anot..."

# Auto-adaptive
abbrev_label(labels, "auto")

Run the code above in your browser using DataLab