mlegend: mlegend

View source: R/plot_extra.R

mlegendR Documentation

mlegend

Description

Stack multiple legends.

Usage

mlegend(x, y = NULL, legend, horizontal = FALSE, ...)

Arguments

x, y

the x- and y-coordinates to be used or a keyword, see xy.coords; note that this is only used for the first legend, and the coordinates for subsequent legends are automatically calculated from the previous legend

legend

a list or list of lists of arguments passed to legend with each list corresponding to a single legend

horizontal

logical; if TRUE, stack legends horizontally

...

additional arguments passed to all legends, e.g., to set defaults; these will be over-ridden in individual legends by passing a list of arguments to legend

Value

A data frame of data.frame(legend(...)) for each legend with the legend index to distinguish multiple legends. Note that the number of rows in each group depends on the number of values in each legend.

Examples

op <- par(mfrow = c(1, 2))
plot(1)
l <- list(
  legend = 'first\nlegend', fill = 'red'
)
mlegend('topleft', legend = l)

l <- list(
  l,
  list(
    legend = 'second legend', fill = 'blue'
  ),
  list(
    legend = letters[1:5], pch = 16, col = 1:5, bty = 'n'
  ),
  list(
    legend = LETTERS[1:3], horiz = TRUE, lty = 1, col = 1:3
  ),
  list(
    legend = 'final legend'
  )
)

mlegend('left', legend = l, horizontal = TRUE)

## dot arguments will be applied to all legends
mlegend('topright', legend = l, bty = 'n', inset = c(-0.5, 0), xpd = NA)
par(op)


raredd/rawr documentation built on April 29, 2024, 10:29 a.m.