Skip to contents

Provides a colour scheme that map a numeric vector to colours.

Usage

ramp(x, palette, midpoint = NULL, ...)

Arguments

x

A numeric vector to be mapped to colours.

palette

A character string giving the name of the palette to be used (see colour()).

midpoint

A numeric value specifying the midpoint of x. If not NULL, x will be rescaled to have the specified midpoint.

...

Further arguments passed to colour().

Value

A palette function with the following attributes, that when called with a single argument (the number of levels, e.g. the breaks returned by hist()) returns a vector of colours.

See also

Other colour palettes: colour(), info(), scale_picker

Author

N. Frerebeau

Examples

## Visualize a simple DEM model

## Distribution of elevation values
elevation <- hist(volcano)


## Where are breaks?
elevation$breaks
#>  [1]  90 100 110 120 130 140 150 160 170 180 190 200

## No rescaling
ramp_default <- ramp(elevation$breaks, palette = "BuRd")(10)
image(volcano, col = ramp_default)
legend("topright", legend = attr(ramp_default, "breaks"), fill = ramp_default)


## Rescale to midpoint
ramp_160 <- ramp(elevation$breaks, palette = "BuRd", midpoint = 160)(10)
image(volcano, col = ramp_160)
legend("topright", legend = attr(ramp_160, "breaks"), fill = ramp_160)