mapLegend: Add a color scale legend to a heat map

Description Usage Arguments Examples

View source: R/mapLegend.R

Description

Adds a bar that associates numeric values with colors. Useful for ay plot that uses a linear color gradient to indicate a numeric value, and for which there are too many colors/ values to specify each individually.

Usage

1
2
mapLegend(x = 0.9, y = 0.2, w = 0.05, h = 0.25, zlim, cols,
  horiz = FALSE, axSide, adj, offset, lab.cex = 1, lab.sig = 2)

Arguments

x, y

the locations of the center of the legend, as a proportion of plot area (between 0 and 1)

w, h

the width and height of the legend, as a proportion of plot area

zlim

lower and upper limit of values indicated by colors

cols

colors used in the original plot; e.g., created by zCol. Note that it is assumed that color and the value change linearly

horiz

Logical, if FALSE (default), the colors in the legend change long the vertical axis

axSide

the side of the color bar on which the axis (line, ticks, labels) should be placed; if missing, reasonable default is chosen

adj

length 1 or 2 numeric vector to be passed to text that will affect the position of the tick marks; if missing, reasonable default is chosen

offset

length 1 numeric vector to be passed to text that will affect the position of the axis labels; if missing, reasonable default is chosen

lab.cex

numeric value to be passed to cex argument of text that will affect the size of the axis labels

lab.sig

integer, the number of significant digits to which the axis labels should be rounded; see signif

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data(volcano)
v <- volcano
v[v<=quantile(v,0.2)] <- NA # small values to NA (will plot white)
v_cols <- zCol(256, 1:256)
image(v, col=v_cols)
zl <- range(v, na.rm=TRUE)
mapLegend(x=0.9, y=0.85, zlim=zl, cols=v_cols)
mapLegend(x=0.975, y=0.075, zlim=zl, cols=v_cols, w=0.025, h=0.125)
mapLegend(x=0.73, y=0.975, zlim=zl, cols=v_cols, w=0.125, h=0.025, horiz=TRUE)
mapLegend(x=0.93, y=0.25, zlim=zl, cols=v_cols, w=0.1, h=0.025, horiz=TRUE)

rBatt/rbLib documentation built on May 26, 2019, 7:45 p.m.