labeller: Add labels to a plot

View source: R/plot_extra.R

labellerR Documentation

Add labels to a plot

Description

Adds a figure label or sub label to an existing plot.

Usage

labeller(
  fig = NULL,
  sub = NULL,
  side = 3L,
  pad = NULL,
  at = c(0.05, 0.9),
  args.fig = list(),
  args.sub = list(),
  args.rect = list()
)

Arguments

fig, sub

labels for the upper left corner and panel, respectively; note that side controls where sub is placed

side

the side of the plot to draw the sub label

pad

(optional) height of the sub label space as a fraction of the length of the axis perpendicular to side

at

the x- and y-locations of fig given in normalized figure coordinates; see convertXY

args.fig, args.sub, args.rect

a named list of additional arguments passed to text, text, and rect, respectively

Examples

op <- par(mar = c(5, 5, 5, 5))
plot(1, ylim = c(0, 100))
labeller(fig = 'A')
labeller(fig = 'A', at = c(0.025, 0.9), args.fig = list(font = 2, cex = 2))
labeller(sub = 'this is a\nplot label')
labeller(sub = 'plot label', side = 4)
labeller(sub = 'pad = -0.1', side = 2, pad = -0.1)
labeller(
  sub = 'plot label', side = 1,
  args.sub = list(cex = 3, font = 2, col = 'white'),
  args.rect = list(col = 'red', lwd = 3, border = 'orange', lty = 2)
)
par(op)

op <- par(mfrow = c(2, 3))
sapply(1:6, function(ii) {
  plot(1)
  fig <- names(plotr::fig(ii, par('mfrow')))
  labeller(LETTERS[ii], sprintf('Panel %s', ii), side = 3L + grepl('right', fig))
})
par(op)


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.