panel.key: Draw custom keys inside lattice plots

panel.keyR Documentation

Draw custom keys inside lattice plots

Description

This panel function allows to draw a key (legend) inside a lattice panel, with more customization options than the lattice default.

Usage

panel.key(
  groups = NULL,
  labels = NULL,
  which.panel = 1,
  pch = lattice::trellis.par.get()$superpose.symbol$pch,
  cex = lattice::trellis.par.get()$superpose.symbol$cex,
  point.cex = NULL,
  alpha = 1,
  points = TRUE,
  lines = FALSE,
  rectangles = FALSE,
  col = NULL,
  lwd = trellis.par.get()$superpose.line$lwd[1],
  lty = trellis.par.get()$superpose.line$lty[1],
  corner = c(0.1, 0.9),
  background = NA,
  ...
)

Arguments

groups

grouping variable passed down from xyplot (does not need to be specified)

labels

(character) list of the labels to draw

which.panel

(numeric) the panel(s) where key(s) should be drawn

points

(logical) if points should be drawn

lines

(logical) if lines should be drawn

rectangles

(logical) if rectangles should be drawn

col, lwd, lty, pch, cex, alpha, point.cex

graphical parameters to draw key labels and symbols

corner

(numeric) vector of length 2 indicating the position of the key, in Normalised Parent Coordinates (0 to 1)

background

(character) color used to draw a background behind the key (default: NA)

...

other arguments passed to the function

Examples

library(lattice)
data(mtcars)

# Two examples for a custom lattice key inside a panel.
# The first takes all arguments from the 
# top-level plotting function.
# The second has custom arguments.
xyplot(mpg ~ 1/wt | factor(vs), mtcars,
  groups = carb, pch = 19,
  panel = function(x, y, ...) {
    panel.xyplot(x, y, ...)
    panel.key(...)
    panel.key(labels = letters[1:5], which.panel = 2, 
      corner = c(0.9, 0.1), col = 1:5, pch = 1:5)
  }
)


m-jahn/lattice-tools documentation built on Dec. 3, 2023, 11:14 p.m.