Learn R Programming

inlmisc (version 0.3.2)

AddGradientLegend: Add Color Gradient Legend to Plot

Description

This function can be used to add a continuous color gradient legend strip to a plot.

Usage

AddGradientLegend(breaks, pal, at = NULL, n = 5L, labels = TRUE,
  scientific = FALSE, title = NULL, loc = c("bottomleft", "topleft",
  "topright", "bottomright"), inset = 0, strip.dim = c(2, 8))

Arguments

breaks

'numeric'. Set of finite numeric breakpoints for the colors.

pal

'function'. Color palette

at

'numeric'. Vector of points at which tick-marks and labels are to be drawn.

n

'integer'. Desired number of tick-marks to be drawn. Unused if at argument is specified.

labels

'logical' or 'character'. Can either be a logical value specifying whether (numerical) annotations are to be made at the tickmarks, or a character or expression vector of labels to be placed at the tickpoints.

scientific

'logical'. Indicates if labels should be formatted for scientific notation, see ToScientific for details.

title

'character'. Title to be placed at the top of the legend.

loc

'character'. Position of the legend in the main plot region: "bottomleft", "topleft", "topright", or "bottomright" to denote legend location.

inset

'numeric'. Inset distance(s) from the margins as a fraction of the plot region.

strip.dim

'numeric'. Dimensions of the color strip, in picas.

Value

Used for the side-effect of a legend drawn on the current graphics device.

See Also

PlotMap

Examples

Run this code
# NOT RUN {
plot(NA, xlim = c(0, 100), ylim = c(-10, 10), xlab = "", ylab = "")
breaks <- 0:200
AddGradientLegend(breaks, rainbow, title = "Title")
AddGradientLegend(breaks, rainbow, title = "Title", inset = c(0.2, 0.1))
breaks <- seq(0, 2e+06, length.out = 5)
AddGradientLegend(breaks, rainbow, loc = "topright", inset = 0.1)
pal <- function(...) rev(rainbow(...))  # reverse colors in palette
AddGradientLegend(breaks, pal, loc = "bottomright", inset = c(0.2, 0.1),
                  scientific = TRUE, strip.dim = c(1, 14))

# }

Run the code above in your browser using DataLab