Skip to contents

Create gradient colors

Usage

val_to_color(x, vals = NULL, low = "blue", high = "red", alpha = 1)

Arguments

x

Numeric value(s) to convert to colors (e.g., a vector of heights).

vals

A numeric vector holding all possible values of x to determine the color gradient range.

low

Color corresponding to the minimum value in vals (default: "blue").

high

Color corresponding to the maximum value in vals (default: "red").

alpha

Opacity level between 0 and 1 (default: 1).

Value

A vector of hex color codes corresponding to the input values x.

Examples

x = rnorm(1e3)
plot(seq(x), x, col= val_to_color(x), pch=19)