Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Colour

R provides a collection of predefined colours which you can use to name colours, where appropriate. The list of colours is obtained from the colour function:

> colours()
  [1] "white"                "aliceblue"            "antiquewhite"        
  [4] "antiquewhite1"        "antiquewhite2"        "antiquewhite3"       
  [7] "antiquewhite4"        "aquamarine"           "aquamarine1"         
 [10] "aquamarine2"          "aquamarine3"          "aquamarine4"         
 [13] "azure"                "azure1"               "azure2"              
 [16] "azure3"               "azure4"               "beige"               
 [19] "bisque"               "bisque1"              "bisque2"             
[...]
[646] "wheat"                "wheat1"               "wheat2"              
[649] "wheat3"               "wheat4"               "whitesmoke"          
[652] "yellow"               "yellow1"              "yellow2"             
[655] "yellow3"              "yellow4"              "yellowgreen"

There's plenty of colours there to choose from!

The col option of a plot is used to change any default colours used by a plot. You can supply a list of integers which will index the output of a call to the palette function. The default palette is:

> palette()
[1] "black"   "red"     "green3"  "blue"    "cyan"    "magenta" "yellow" 
[8] "gray"

You can generate a contiguous colour palette using cm.colors.

> cm.colors(10)
 [1] "#80FFFF" "#99FFFF" "#B2FFFF" "#CCFFFF" "#E6FFFF" "#FFE6FF" "#FFCCFF"
 [8] "#FFB2FF" "#FF99FF" "#FF80FF"

Similarly, to generate a sequence of colours from a rainbow:

> rainbow(10)
 [1] "#FF0000" "#FF9900" "#CCFF00" "#33FF00" "#00FF66" "#00FFFF" "#0066FF"
 [8] "#3300FF" "#CC00FF" "#FF0099"

To generate a sequence of six grays you can use the gray function:

> gray(seq(0.1, 0.9, len=6))
[1] "#1A1A1A" "#424242" "#6B6B6B" "#949494" "#BDBDBD" "#E6E6E6"



Copyright © 2004-2006 Graham.Williams@togaware.com
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.