Colour Lookup Tables
Create a colour map (colour lookup table).
colourmap(col, ..., range=NULL, breaks=NULL, inputs=NULL)
- Vector of values specifying colours
- Interval to be mapped.
A numeric vector of length 2, specifying the endpoints of the
range of values to be mapped.
- Values to which the colours are associated.
A factor or vector of the same length as
col. Incompatible with
- Breakpoints for the colour map.
A numeric vector of length equal to
length(col)+1. Incompatible with
A colour map is a mechanism for associating colours with data. It can be regarded as a function, mapping data to colours.
colourmap creates an object representing
a colour map, which can then be used to control the plot commands
col specifies the colours to which
data values will be mapped. It should be a vector
whose entries can be interpreted as colours by the standard
Rgraphics system. The entries can be string names of colours
"red", or integers that refer to
colours in the standard palette, or strings containing
six-letter hexadecimal codes like
Exactly one of the arguments
must be specified by name.
inputs is given, then it should be a vector or factor,
of the same length as
col. The entries of
inputs can be
any atomic type (e.g. numeric, logical, character, complex) or factor
values. The resulting colour map associates the value
with the colour
range is given, then it determines the interval of the real
number line that will be mapped. It should be a numeric vector of
breaks is given, then it determines the precise intervals
of the real number line
which are mapped to each colour. It should be a numeric vector,
of length at least 2, with entries that are in increasing order.
Infinite values are allowed. Any number in the range
breaks[i+1] will be mapped to the
The result is an object of class
plot methods for this class.
Some plot commands in the
The result is also a function
f which can be used to compute
the colour assigned to any data value.
f(x) returns the character value of the colour assigned
x. This also works for vectors of data values.
- A function, which is also an object of class
The plot method
See the Rhelp file on
colours for information about the colours
that Rrecognises, and how to manipulate them.
To make a smooth transition between colours, see
To alter individual colour values, see
for more tools to manipulate colour values.
lut for lookup tables.
# colour map for real numbers, using breakpoints cr <- colourmap(c("red", "blue", "green"), breaks=c(0,5,10,15)) cr cr(3.2) cr(c(3,5,7)) # a large colour map co <- colourmap(rainbow(100), range=c(-1,1)) co(0.2) # colour map for discrete set of values ct <- colourmap(c("red", "green"), inputs=c(FALSE, TRUE)) ct(TRUE)