Learn R Programming

condvis (version 0.2-2)

cont2color: Convert continuous variable to suitable graded colors.

Description

Convert continuous variable to suitable graded colors, using RColorBrewer if it is installed.

Usage

cont2color(x, xrange = NULL, breaks = NULL, colors = NULL)

Arguments

x
a numeric vector
xrange
a vector of length 2 denoting the boundaries for the colors at either end of the color scale. All values outside this range will be assigned the same color according to which side of the range they fall. Defaults to range(x)
breaks
an integer denoting the number of splits between different color levels. Defaults to 11. Needs to be set if colors is specified.
colors
optional color vector. Default value is a diverging color scheme (either "PiYG" from RColorBrewer if available, or cm.colors). Otherwise, a vector of colors may be spec

Value

  • A vector of colors.

Details

Uses the RColorBrewer package, if installed.

See Also

factor2color

Examples

Run this code
x <- runif(200)
plot(x, col = cont2color(x, c(0,1)))

plot(x, col = cont2color(x, c(0,0.5)))

plot(sort(x), col = cont2color(sort(x), c(0.25,0.75)), pch = 16)
abline(h = c(0.25, 0.75), lty = 3)

Run the code above in your browser using DataLab