Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

colorpanel

Generate a smoothly varying set of colors


Description

colorpanel generate a set of colors that varies smoothly. redgreen, greenred, bluered, and redblue generate red-black-green, green-black-red, red-white-blue, and blue-white-red colorbars, respectively. colors

Usage

colorpanel(n, low, mid, high)
redgreen(n)
greenred(n)
bluered(n)
redblue(n)

Arguments

n

Desired number of color elements in the panel.

low, mid, high

Colors to use for the Lowest, middle, and highest values. mid may be ommited.

Details

The values for low, mid, high can be given as color names ('red'), plot color index (2=red), and HTML-style RGB, ("\#FF0000"=red).

If mid is supplied, then the returned color panel will consist of n - floor(n/2) HTML-style RGB elements which vary smoothly between low and mid, then between mid and high. Note that if n is even, the color mid will occur twice at the center of the sequence.

If mid is omitted, the color panel will vary smoothly beween low and high.

Value

Vector of HTML-style RGB colors.

Author(s)

Gregory R. Warnes greg@warnes.net

See Also

Examples

showpanel <- function(col)
{
  image(z=matrix(1:100, ncol=1), col=col, xaxt="n", yaxt="n" )
}

par(mfrow=c(3,3))

# two colors only:
showpanel(colorpanel(8,low="red",high="green"))

# three colors
showpanel(colorpanel(8,"red","black","green"))
# note the duplicatation of black at the center, using an odd
# number of elements resolves this:
showpanel(colorpanel(9,"red","black","green"))

showpanel(greenred(64))
showpanel(redgreen(64))
showpanel(bluered(64))
showpanel(redblue(64))

gplots

Various R Programming Tools for Plotting Data

v3.1.1
GPL-2
Authors
Gregory R. Warnes [aut], Ben Bolker [aut], Lodewijk Bonebakker [aut], Robert Gentleman [aut], Wolfgang Huber [aut], Andy Liaw [aut], Thomas Lumley [aut], Martin Maechler [aut], Arni Magnusson [aut], Steffen Moeller [aut], Marc Schwartz [aut], Bill Venables [aut], Tal Galili [ctb, cre]
Initial release
2020-11-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.