Skip to contents

factor() returns a value carrying only levels and class, so it silently drops the variable label that get_raw_labels() and the plot titles read. Everything factor() does not set itself is copied back.

Usage

relevel_preserving_attributes(x, levels)

Arguments

x

A factor or vector to reorder

levels

Desired level order. Observed values it does not mention keep their place at the end rather than becoming NA.

Value

x with its levels reordered and its attributes intact