Below is some example R code that generates a few plots, coloured by RColorBrewer.
The colours are split into three group, sequential, diverging, and qualitative.
- Sequential - Light colours for low data, dark for high data
- Diverging - Light colours for mid-range data, low and high contrasting dark colours
- Qualitative - Colours designed to give maximum visual difference between classes
The main function is brewer.pal, which you simply give the number of colours you want, and the name of the palette, which you can choose from running display.brewer.all()
There are limits on the number of colours you can get, but if you want to extend the Sequential or Diverging groups you can do so with the colorRampPalatte command, for example :
There are limits on the number of colours you can get, but if you want to extend the Sequential or Diverging groups you can do so with the colorRampPalatte command, for example :
colorRampPalette(brewer.pal(9,"Blues"))(100)
This will generate 100 colours based on the 9 from the 'Blues' palette. See image below for a contrast.
From compBiomeBlog |
Hi Stew -
ReplyDeleteThis is great, we just had this problem and came across colorbrewer as a site for solving this manually. Didn't know there was an R package, so thanks for the tip!
- Casey
I use this in almost all my scripts, it is in the standard header for my Rcode.
ReplyDeleteHi Stew,
ReplyDeleteI just came by your blog. Great post - thank you!
Question: Wanna join R-bloggers.com?
If so, head over to:
http://www.r-bloggers.com/add-your-blog/
Cheers,
Tal