View source: R/factor_labels.R
| set_factor_labels | R Documentation |
Store substantive names for factors (e.g. "Neuroticism" for "m5f1") on
the object itself, so that print(), summary(),
tidy(), autoplot(), and
top_items() display them without re-supplying the labels each time. This is
the factor-label counterpart to item / variable labels (see
top_items() and ?ackwards); the two are distinct and never interchanged.
set_factor_labels(x, labels)
x |
An |
labels |
A named character vector mapping factor IDs ( |
Labels are display only – they never change a factor's stable ID
(m{k}f{j}), and every lineage / edge / score column continues to key on the
ID. A factor with no label falls back to its ID everywhere. The stored labels
ride along through prune(), boot_edges(), augment(),
and predict() unchanged.
The ackwards object, with meta$factor_labels updated. Pipeable.
set_factor_labels() merges into any labels already stored, so you can
build them up incrementally. Within a single call:
a normal string sets (or overwrites) that factor's label;
an NA or "" value removes just that factor's label;
passing labels = NULL clears all labels at once.
The scaffold printed by label_template() is a convenient starting point:
copy its c(...) literal, fill in the substantive names, and pass it here.
factor_labels() to read them back, label_template() for a
ready-to-edit scaffold, autoplot.ackwards() (node_labels overrides a
stored label per node).
x <- ackwards(sim16, k_max = 4, engine = "pca")
# Start from a scaffold, fill in names, attach them:
x <- set_factor_labels(x, c(m4f1 = "Alpha", m4f2 = "Beta"))
factor_labels(x)
# Merge in more; remove one; everything downstream now shows the labels:
x <- set_factor_labels(x, c(m2f1 = "Broad", m4f2 = NA))
summary(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.