This function relabels the facet strip labels in a plot created by a wrap_* function (e.g., wrap_eta_cont(), wrap_cont_cont()) by looking up the facet variable names in a named list or yspec object. Variable names are discovered automatically from the plot data. Names absent from spec and labs are left unchanged.

pmp_relabel_wrap(
  p,
  spec,
  labs = list(),
  short_max = Inf,
  f_break = Inf,
  unit_break = FALSE
)

Arguments

p

a ggplot object created by a wrap_* pmplots function.

spec

a named list of label data; names correspond to columns in the data used to make the plot; may also be a yspec object, which will be converted to a named list through yspec::ys_get_short_unit().

labs

another object like spec containing of label data to override names found in spec.

short_max

passed to yspec::ys_get_short_unit() when spec is a yspec object.

f_break

character width at which to insert a single line break in facet strip labels; defaults to Inf (no break); when the resolved label exceeds this width, a single newline is inserted at the last word boundary at or before the limit.

unit_break

if TRUE, a newline is inserted between the label text and a trailing parenthetical unit (e.g., "Weight (kg)" becomes "Weight\n(kg)"); defaults to FALSE.

Value

The plot p with updated facet strip labels.

Examples

data <- pmplots_data_obs()

spec <- list(WT = "Weight (kg)", ALB = "Albumin (mg/dL)")

p <- wrap_eta_cont(data, x = c("WT", "ALB"), y = "ETA1//ETA1", scales = "free_x")

pmp_relabel_wrap(p, spec)
#> `geom_smooth()` using formula = 'y ~ x'