colmap: Create a color gradient function

View source: R/yogitools.R

colmapR Documentation

Create a color gradient function

Description

Creates a color gradient function that maps numerical values to colors on a gradient. Multiple stops in the gradient can be defined as different input colors and be assigned to numerical values. For example, a gradient could start at '0' with the color blue, transition towards white as it approaches '1' and further transition to red as it approaches '2'. Values outside of the defined range would be mapped to the nearest extreme color; e.g. in the previous example, '3.1' would still map to red.

Usage

colmap(
  valStops = c(0, 1, 2),
  colStops = c("royalblue3", "white", "firebrick3"),
  naCol = "gray"
)

Arguments

valStops

a vector listing the numerical values mapped to the color stops. Defaults to c(0,1,2).

colStops

a vector of color strings. Defaults to c("royalblue3","white","firebrick3").

naCol

the color to assign to NA values. Defaults to "gray"

Value

a function accepting a numerical vector as input, which will produce the corresponding color vector.

Examples

mycolmap <- colmap(c(0,1,2),c("royalblue3","white","firebrick3"),naCol="gray")
mycolors <- mycolmap(seq(0,2,0.01))

jweile/yogitools documentation built on May 11, 2023, 7:42 p.m.