| number2color {npreg} | R Documentation |
Map Numbers to Colors
Description
Each of the n elements of a numeric vector is mapped onto one of the m specified colors.
Usage
number2color(x, colors, ncol = 21, equidistant = TRUE, xmin = min(x), xmax = max(x))
Arguments
x |
numeric vector of observations that should be mapped to colors |
colors |
an optional vector of colors (see Note for default colors) |
ncol |
number of colors |
equidistant |
if |
xmin |
minimum |
xmax |
maximum |
Details
Elements of a numeric vector are binned using either an equidistant sequence (default) or sample quantiles. Each bin is associated with a unique color, so binning the observations is equivalent to mapping the numbers to colors. The colors are input to the colorRampPalette function to create a color palette with length specified by the ncol argument.
Value
Returns of vector of colors the same length as x
Note
If colors is missing, the default color palette is defined as
colors <- c("darkblue", rainbow(12)[c(9, 8, 7, 5, 3, 2, 1)], "darkred")
which is a modified version of the rainbow color palette.
Author(s)
Nathaniel E. Helwig <helwig@umn.edu>
See Also
.bincode is used to bin the data
Examples
x <- 1:100
xcol <- number2color(x)
plot(x, col = xcol)