Learn R Programming

rje (version 1.9)

cubeHelix: Cube Helix colour palette

Description

Cube Helix is a colour scheme designed to be appropriate for screen display of intensity images. The scheme is intended to be monotonically increasing in brightness when displayed in greyscale. This might also provide improved visualisation for colour blindness sufferers.

Usage

cubeHelix(n, start = 0.5, r = -1.5, hue = 1, gamma = 1)

Arguments

n

integer giving the number of colours in the scale

start

numeric: start gives the initial angle (in radians) of the helix

r

numeric: number of rotations of the helix over the scale; can be negative

hue

numeric controling the saturation of colour: 0 gives pure greyscale, defaults to 1

gamma

numeric which can be used to emphasise lower or higher intensity values, defaults to 1

Value

Vector of RGB colours (strings) of length n.

Details

The function evaluates a helix which moves through the RGB "cube", beginning at black (0,0,0) and finishing at white (1,1,1). Evenly spaced points on this helix in the cube are returned as RGB colours. This provides a colour palette in which intensity increases monotonically, which makes for good transfer to greyscale displays or printouts. This also may have advantages for colour blindeness sufferers. See references for further details.

References

Green, D. A., 2011, A colour scheme for the display of astronomical intensity images. Bulletin of the Astronomical Society of India, 39, 289. http://adsabs.harvard.edu/abs/2011BASI...39..289G

See Dave Green's page at http://www.mrao.cam.ac.uk/~dag/CUBEHELIX/ for other details.

See Also

rainbow (for other colour palettes).

Examples

Run this code
# NOT RUN {
cubeHelix(21)

# }
# NOT RUN {
cols = cubeHelix(101)

plot.new()
plot.window(xlim=c(0,1), ylim=c(0,1))
axis(side=1)
for (i in 1:101) {
  rect((i-1)/101,0,(i+0.1)/101,1, col=cols[i], lwd=0)
}
# }
# NOT RUN {
# }
# NOT RUN {
require(grDevices)
# comparison with other palettes
n = 101
cols = cubeHelix(n)
heat = heat.colors(n)
rain = rainbow(n)
terr = terrain.colors(n)

plot.new()
plot.window(xlim=c(-0.5,1), ylim=c(0,4))
axis(side=1, at=c(0,1))
axis(side=2, at=1:4-0.5, labels=1:4, pos=0)
for (i in 1:n) {
  rect((i-1)/n,3,(i+0.1)/n,3.9, col=cols[i], lwd=0)
  rect((i-1)/n,2,(i+0.1)/n,2.9, col=heat[i], lwd=0)
  rect((i-1)/n,1,(i+0.1)/n,1.9, col=rain[i], lwd=0)
  rect((i-1)/n,0,(i+0.1)/n,0.9, col=terr[i], lwd=0)
}
legend(-0.6,4,legend=c("4. cube helix", "3. heat", "2. rainbow", "1. terrain"), box.lwd=0)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab