ColorLegend: Legend for color maps

View source: R/ColorLegend.R

ColorLegendR Documentation

Legend for color maps

Description

ColorLegend draws a color legend according to given color mapping parameters.

Usage

ColorLegend(
  pos,
  parameters,
  ticks = NULL,
  labels = NULL,
  resolution = 100,
  log = FALSE,
  xpd = FALSE,
  size = c(40, 3),
  margin = 5,
  horiz = FALSE,
  tick.pos = 1,
  tick.size = 1.5,
  offset = 0.3,
  lwd = 1,
  border = TRUE,
  ...
)

Arguments

pos

the legend location which can be specified using either a single keyword in "bottomright", "bottom", "bottomleft", "left", "center", "right", "topleft", "top", "topright", or the corresponding abbreviation ("br", "b", "bl", "l", "c", "r", "tl", "t", "tr"), or the corresponding index (from 1 for "bottomright" to 9 for "topleft").

parameters

a ColorParameters object defined with DefineColorMap.

ticks

values of the tick marks for graduation of the color scale (default = thresholds as defined in parameters).

labels

text labels shown next to the tick marks (default = ticks).

resolution

the resolution of the color scale or number of elementary units composing the represented color gradients (default = 100).

log

logical. If TRUE, the color legend is represented in log scale (default = FALSE).

xpd

logical. If FALSE, the legend position is relative to the plot region (default). If TRUE, the legend position is relative to the entire device region. This second option works fine for separated plots but not for multipanel layouts (see layout).

size

the size of the color legend given as a list or a vector in the form c(axial length, width) which are expressed in percentage of the dimensions of the plot area (default = c(40, 3)).

margin

numeric vector controlling the spacing between the legend and the borders of the plot area and expressed in percentage of its dimensions (default = c(5, 5, 5, 5) for left, right, bottom, top).

horiz

logical controlling the legend layout. If TRUE the color legend spans horizontally from the given location, and vertically otherwise (default = FALSE, vertical).

tick.pos

relative location of graduations, which is indicated by a value of 1 or -1 for a location to the right/above or to the left/below the color scale respectively.

tick.size

length of the tick marks, expressed in percentage of the dimensions of the plot area (default = 1.5).

offset

spacing between tick marks and tick labels.

lwd

line width for tick marks and color scale borders.

border

logical activating the drawing of black borders around the color scale (default = TRUE).

...

optional parameters forwarded to the text function.

See Also

MakeColors, DefineColorMap

Examples


# Radial color gradient with two normally distributed random variables
x <- rnorm(2000)
y <- rnorm(2000)
z <- 10^sqrt(x^2 + y^2)

col.par <- DefineColorMap(name = "bantignies")
clrs    <- MakeColors(z, parameters = col.par)

plot(x, y, xlim = c(-4.5, 4.5), ylim = c(-5, 4), pch = 20, col = clrs)
ColorLegend(
  "bottom", parameters = col.par, log = TRUE, size = c(70, 3), horiz = TRUE
)

benja0x40/Barbouille documentation built on March 26, 2023, 11:38 p.m.