This function generates labels for ggplot aesthetics based on the data columns used to create the plot, looking up in a named list or yspec object. See pmp_gg_labs() to label x- and y- axes in plots generated by pmplots functions.

pm_gg_labs(
  spec = list(),
  labs = list(),
  x = NULL,
  y = NULL,
  fill = NULL,
  colour = NULL,
  color = NULL,
  col = NULL,
  linetype = NULL,
  lty = NULL,
  shape = NULL,
  quietly = FALSE,
  short_max = Inf,
  x_break = Inf,
  y_break = Inf,
  var_break = list(),
  ...
)

Arguments

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.

x

label for the x aesthetic; if NULL, resolved via the mapped column name. Pass a column name as a plain string to look it up in spec or labs; wrap in I() to use the string as a literal label.

y

label for the y aesthetic; see x.

fill

label for the fill aesthetic; see x.

colour, color, col

label for the colour aesthetic; see x.

linetype, lty

label for the linetype aesthetic; see x.

shape

label for the shape aesthetic; see x.

quietly

if FALSE, inform when the same aesthetic is mapped to multiple variables that each have a spec entry but resolve to different labels.

short_max

passed to yspec::ys_get_short_unit().

x_break

character width at which to insert a single line break in the x axis label; 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.

y_break

character width at which to insert a single line break in the y axis label; see x_break.

var_break

a named list or named numeric vector; names refer to variables in spec or labs, and each value is passed as the width argument to str_break() to insert a newline in that variable's label. Applied variable-by-variable before axis labels are resolved; keys absent from spec/labs are silently ignored.

...

additional arguments passed to ggplot2::labs().

Value

A pm_gg_labs object that can be added to a pmplots gg object with +.

Details

In case multiple aesthetics are found, the aesthetics in the top-most layer will be used. The user will be informed in case multiple aesthetics are involved that resolve to different names. This situation should be rare; use the quietly argument to suppress notification to the console.

Examples


if(requireNamespace("yspec")) {
library(ggplot2)

library(yspec)

spec <- ys_help$spec()

spec <- update_short(spec, TIME = "Time")

data <- ys_help$data()

p <- ggplot(data, aes(TIME, DV)) + geom_point()

p + pm_gg_labs(spec)

}
#> Loading required namespace: yspec