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.
Usage
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
yspecobject, which will be converted to a named list throughyspec::ys_get_short_unit().- labs
another object like
speccontaining of label data to override names found inspec.- short_max
passed to
yspec::ys_get_short_unit()whenspecis ayspecobject.- 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 toFALSE.
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'
