Learn R Programming

vcd (version 0.9-0)

grid_legend: Legend Function for grid Graphics

Description

This function can be used to add legends to grid-based plots.

Usage

grid_legend(x, y, pch, col, labels, frame = TRUE, hgap = unit(0.5, "lines"),
  vgap = unit(0.3, "lines"), default_units = "lines", gp = gpar(),
  draw = TRUE, title = "Legend:")

Arguments

x, y
coordinates of the legend
pch
integer vector of plotting symbols
col
character vector of colors for the symbols
labels
character vector of labels corresponding to the symbols
frame
logical indicating whether the legend should have a border or not.
hgap
object of class "unit" specifying the space between symbols and labels
vgap
object of class "unit" specifying the space between the lines
default_units
character string indicating the default unit
gp
object of class "gpar" used for the legend
draw
logical indicating whether the legend be drawn or not.
title
character string indicating the plot's title

Value

  • Invisibly, the legend as a "grob" object.

See Also

legend

Examples

Run this code
data(Lifeboats)
attach(Lifeboats)
ternaryplot(Lifeboats[,4:6],
  pch = ifelse(side == "Port", 1, 19),
  col = ifelse(side == "Port", "red", "blue"),
  id  = ifelse(men / total > 0.1, as.character(boat), NA),
  prop_size = 2,
  dimnames_position = "edge",
  main = "Lifeboats on Titanic")
grid_legend(0.8, 0.9, c(1, 19), c("red", "blue"),
  c("Port", "Starboard"), title = "SIDE")

Run the code above in your browser using DataLab