Learn R Programming

TreeTools (version 1.7.3)

SpectrumLegend: Produce a legend for continuous gradient scales

Description

Prints an annotated vertical bar coloured according to a continuous palette.

Usage

SpectrumLegend(
  x0 = 0.05,
  y0 = 0.05,
  x1 = x0,
  y1 = y0 + 0.2,
  absolute = FALSE,
  legend = character(0),
  palette,
  lwd = 4,
  lty = 1,
  lend = "square",
  pos = 4,
  ...
)

Arguments

x0, y0, x1, y1

Coordinates of the bottom-left and top-right end of the bar.

absolute

Logical specifying whether x and y values denote coordinates (TRUE) or relative position, where (0, 0) denotes the bottom-left of the plot area and (1, 1) the top right.

legend

Character vector with which to label points on palette.

palette

Colour palette to depict.

lwd, lty, lend

Additional parameters to segments(), controlling line style.

pos, ...

Additional parameters to text().

Author

Martin R. Smith (martin.smith@durham.ac.uk)

Details

This convenience function is not yet very customizable; do file a GitHub issue if you would value additional functionality.

Examples

Run this code
plot(0:1, 0:1, type = "n", frame.plot = FALSE,
     xlab = "x", ylab = "y")
SpectrumLegend(legend = c("Dark", "Middle", "Bright"),
               palette = hcl.colors(32L), lwd = 5)
SpectrumLegend(0.4, 0.95, 0.9, 0.95, abs = TRUE,
               legend = seq(1, 9, by = 2), palette = 1:9, pos = 1)

Run the code above in your browser using DataLab