number2color: Map Numbers to Colors

View source: R/number2color.R

number2colorR 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 m used for mapping

equidistant

if TRUE (default), the breaks used for binning are an equidistant seqeunce of values spanning the range of x. Otherwise sample quantiles of x are used to define the bin breaks.

xmin

minimum x value to use when defining breaks

xmax

maximum x value to use when defining breaks

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)

npreg documentation built on July 21, 2022, 1:06 a.m.

Related to number2color in npreg...