If you like me, are unable to decide whether blue or brown is a better color for graph- color palettes in R are a big help for aesthetically acceptable alternatives.
Using the same graphs, I choose the 5 main kinds of color palettes, using them is as easy as specifying the col= parameter in graphical display in Base Graphs. And I modified the n parameter for number of colors to be used- you can specify more or less depending how much you want the gradient or difference in colors to be.
> hist(VADeaths,col=heat.colors(7)) > hist(VADeaths,col=terrain.colors(7))
> hist(VADeaths,col=topo.colors(8)) # I increased the colors to 8, since there are 8 bins to prevent repetion > hist(VADeaths,col=cm.colors(8)) > hist(VADeaths,col=cm.colors(10)) # I increased the colors to 10, to showcase the difference in using less or more colors
finally I went to Pretty R at http://www.inside-r.org/pretty-r/tool and made my code more colorful-
I guess on my wishlist/dreamlist/amazon gift list is for GGplot 3/Deducer to have automated color palettes, or even the long promised coming in 2011 Revolution GUI (promised in 2010 roadmap) http://blog.revolutionanalytics.com/2010/05/revolutions-2010-roadmap.html
Create a vector of
n contiguous colors.
rainbow(n, s = 1, v = 1, start = 0, end = max(1,n - 1)/n, gamma = 1, alpha = 1) heat.colors(n, alpha = 1) terrain.colors(n, alpha = 1) topo.colors(n, alpha = 1) cm.colors(n, alpha = 1)
||the number of colors (≥ 1) to be in the palette.|
||the ‘saturation’ and ‘value’ to be used to complete the HSV color descriptions.|
||the (corrected) hue in [0,1] at which the rainbow begins.|
||the (corrected) hue in [0,1] at which the rainbow ends.|
||the gamma correction, see argument
||the alpha transparency, a number in [0,1], see argument
Conceptually, all of these functions actually use (parts of) a line cut out of the 3-dimensional color space, parametrized by
hsv(h,s,v), and hence, equispaced hues in RGB space tend to cluster at the red, green and blue primaries.
Some applications such as contouring require a palette of colors which do not wrap around to give a final color close to the starting one.
rainbow, the parameters
end can be used to specify particular subranges of hues. The following values can be used when generating such a subrange: red=0, yellow=1/6, green=2/6, cyan=3/6, blue=4/6and magenta=5/6.
A character vector,
cv, of color names. This can be used either to create a user–defined color palette for subsequent graphics by
col= specification in graphics functions or in
col2rgb for translating to RGB numbers.
- Top ten business analytics graphs Bar Charts (3/10) (decisionstats.com)