valueToColor: Map numerical values to colors.

View source: R/valueToColor.R

valueToColorR Documentation

Map numerical values to colors.

Description

valueToColor takes a numerical vector and maps each value to an R color string.

Usage

valueToColor(
  x,
  rng = range(x, na.rm = TRUE),
  col = c("#5E4FA2", "#3288BD", "#66C2A5", "#ABDDA4", "#E6F598", "#FFFFBF", "#FEE08B",
    "#FDAE61", "#F46D43", "#D53E4F", "#9E0142"),
  NA.col = "lightgray",
  alpha = NULL
)

Arguments

x

numeric vector with values to be mapped to colors.

rng

numeric(2) giving the range of values to be mapped to colors. By default, this will be the range of finite values in x.

col

vector with R colors defining the palette (must be a valid argument to col2rgb.

NA.col

Single R color to use for NA values in x.

alpha

NULL (default) or numeric(1) between 0 and 255, giving the alpha channel value for the colors (0 = fully transparent, 255 = fully opaque). NULL will use fully opaque colors (alpha = 255). alpha is ignored if col already contain colors with defined alpha values.

Details

The values in [rng[1], rng[2]] will be linearly mapped to the color palette defined by col. Any values in x less (greater) than rng[1] (rng[2]) will be assigned the same color as rng[1] (rng[2]).

Value

A character vector of the same length of x with R colors in hexadecimal string-encoded RGB format.

Author(s)

Michael Stadler

See Also

colorRamp and rgb for the functions called by valueToColor.

Examples

x <- rnorm(1000)
y <- rnorm(1000)
cols <- valueToColor(x + y)
plot(x, y, pch = 20, col = cols, main = "default")


fmicompbio/swissknife documentation built on June 11, 2025, 4:17 p.m.