Learn R Programming

khroma (version 1.10.0)

ramp: Colour Ramp

Description

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

Usage

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

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.

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().

Author

N. Frerebeau

See Also

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

Examples

Run this code
## Visualize a simple DEM model

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

## Where are breaks?
elevation$breaks

## 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)

Run the code above in your browser using DataLab