From QERM Wiki
Revision as of 21:14, 17 April 2008 by Ian (Talk | contribs)
Jump to: navigation, search


Colors in R can be defined by name (blue, black, darkgoldenrod, cornsilk, etc.), according to RGB values, according to HSL and HCL values (variously, permutations of hue, saturation, chroma and luminescence, see: Wikipedia:HSL and HSV and Wikipedia:Munsell color system for more information). Most of these values are freely definable either as decimal values between 0 to 1 or hexadecimal values between 0 and F.

See the colors command for a list of built in colros.

See rgb, hsv and hcl commands for more on defining custom colors.

See heat.colors, topo.colors, cm.colors, and rainbow for automatic generation of appealing color spectra.

For more sophisticated techniques, you can create your own color palette with the colorRamp and colorRampPalette functions. For instance the 'jet color' scheme used in Matlab can be created by:

jet.colors <- 

Here are a few links to handy R color charts:



Many of the functions related to color allow the input of an alpha parameter determining transparency. This often allows an increase in the clarity of the data presented in a plot. The image below was created using the simple commands:



Unfortunately, many devices and file formats do not support transparency. Writing the image from R as a PDF is one of the best choices. The image above was created in the Rgui running in Windows and saved as a .jpg. If your current preferred tools won't support transparency, you might consider setting up Cairo which is an alternative graphics device for R (unfortunately not super-easy to set up):


See Also

R tips

Personal tools