Learn R Programming

npreg (version 1.1.0)

number2color: 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))

Value

Returns of vector of colors the same length as 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

Author

Nathaniel E. Helwig <helwig@umn.edu>

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.

See Also

.bincode is used to bin the data

Examples

Run this code
x <- 1:100
xcol <- number2color(x)
plot(x, col = xcol)

Run the code above in your browser using DataLab