hsvScale: A colour gradient

Description

Provides colours for a vector of values, with colours scaled by the values and ranging from blue (min) to purple (max) via cyan, green, yellow and red. The colours are specified via the hsv function.

Usage

1
hsvScale(v, sat=1, val=0.75, alpha=1, min.v=min(v), max.v=max(v))

Arguments

v

A numeric vector

sat

The saturation of the resulting colors in the range 0-1. A vector or a single value. The values will be recycled for individual colors.

val

The value (i.e. how bright) of the resulting colors. Will be recycled as for sat.

alpha

The alpha values of the resulting colors, recycled as for sat and val.

min.v

The logical minimum of the range of values (to allow comparisons between different vectors). min.v should be equal to or lower than the minimum value in the range, but this is not enforced

max.v

The logical maximum of the range of values.

Value

A vector of colors, one each for the elements in v.
The colors are scaled from blue (lowest) to purple (highest) via cyan, green, yellow and red.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
v <- 1:30
plot(v, rep(1, length(v)), col=hsvScale(v), pch=19, cex=3)

## set the saturation to 0.5
plot(v, rep(1, length(v)), col=hsvScale(v, sat=0.5), pch=19, cex=3)

## cycle saturation values
plot(v, rep(1, length(v)), col=hsvScale(v, sat=c(0.3,0.6,0.9)), pch=19, cex=3)

## set the value to 0.4 (dark colours)
plot(v, rep(1, length(v)), col=hsvScale(v, val=0.5), pch=19, cex=3)

## the colours are not related to the position:
v2 <- sample(v, length(v))
plot(v, rep(1, length(v)), col=hsvScale(v2), pch=19, cex=3)