colorspread: Produces an ordered palate of colours with the same hue.

View source: R/StackedBars.R

colorspreadR Documentation

Produces an ordered palate of colours with the same hue.

Description

This takes a colour specification, and produces an ordered series of colours by manipulating the saturate (and possibly value) of the color, leaving the hue constant. This produces a colour palate suitable for plotting ordered factors, which looks good on a colour display, but also reproduces well on a grayscale printer (or for persons with limited colour perception).

Usage

colorspread(col, steps, maxsat = FALSE, rampval = FALSE)

Arguments

col

A color in any format suitable as input to col2rgb.

steps

A integer describing the number of colors to create.

maxsat

A logical value. If true, the final color in the series will have saturation 1, instead of whatever is appropriate for the input.

rampval

A logical value. If true, the value as well as the saturation of the color is ramped.

Details

The colour is converted to a RGB value using col2rgb and then to an HSV value using rgb2hsv. The saturation is then scaled into steps equal intervals. If requested, the value is scaled as well.

Value

A character vectors of length steps giving the colour palate from lowest to highest intensity. This is suitable to passing to the col argument of most graphics functions.

Note

Many of the built-in colours come with 4 intensity variants are meant to work well together. In some cases an expression like paste("firebrick",1:4,sep="") may work better than colorspread. To see the built-in colours, use the colors function.

Author(s)

Russell Almond

See Also

compareBars, link{stackedBars}

Examples

barplot(rep(1,4),col=colorspread("slategray",4))
barplot(rep(1,4),col=colorspread("slategray",4,maxsat=TRUE))
barplot(rep(1,4),col=colorspread("violetred",4))
barplot(rep(1,4),col=colorspread("violetred",4,rampval=TRUE))

ralmond/CPTtools documentation built on Dec. 27, 2024, 7:15 a.m.