R Color Reference Sheet

April 16, 2013
By

(This article was first published on Brokering Closure » R, and kindly contributed to R-bloggers)

R has a built-in collection of 657 colors that you can use in plotting functions by using color names. There are also various facilities to select color sequences more systematically:

  • Color palettes and ramps available in packages RColorBrewer and colorRamps.
  • R base functions colorRamp and colorRampPalette that you can use to create your own color sequences by interpolating a set of colors that you provide.
  • R base functions rgb, hsv, and hcl that you can use to generate (almost) any color you want.

When producing data visualizations, the choice of proper colors is often a compromise between the requirements dictated by the data visualisation itself and the overall style and color of the article/book/report that the visualization is going to be an element of. Choosing an optimal color palette is not so easy and its handy to have some reference. Inspired by a this sheet by Przemek Biecek I created a variant of an R color reference sheet showing different ways in which you can use and call colors in R when creating visualizations. The sheet fits A4 paper (two pages). On the first page it shows a matrix of all the 657 colors with their names. On the second page, on the left, all palettes from RColorBrewer package are displayed. On the right, selected color ramps available in base R (base package grDevices) and in the contributed package colorRamps. Miniatures below:

rcolorsheet-0 rcolorsheet-1

You can download the sheet as PDF from here.

Below is a gist with the code creating the sheet as a PDF “rcolorsheet.pdf”. Instead of directly reusing the Przemek’s code I have rewritten the parts that produce the first page (built-in color names) and the part with the ramps using the image function. I think it is much simpler, less low-level for-looping and a bit more extensible. For example, it is easy to extend the collection of color ramps by providing just additional function name in the form packagename::functionname to the funnames vector (any extra package would have to be loaded at the top of the script).

To leave a comment for the author, please follow the link and comment on his blog: Brokering Closure » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.