panel.key | R Documentation |
This panel function allows to draw a key (legend) inside a lattice panel, with more customization options than the lattice default.
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,
...
)
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 |
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)
}
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.