colorspread | R Documentation |
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).
colorspread(col, steps, maxsat = FALSE, rampval = FALSE)
col |
A color in any format suitable as input to
|
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. |
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.
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.
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.
Russell Almond
compareBars
, link{stackedBars}
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.