Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color schemes in R?

Tags:

plot

r

Does R have color palettes?

In other words, I am looking for an array of 6 or so color names that go well together in a graph or plot; maybe there are some predefined schemes like that?

like image 821
Frank Avatar asked Sep 30 '10 16:09

Frank


People also ask

What are the palettes in R?

In its simplest form, a palette in R is simply a vector of colors. This vector can be include the hex triplet or R color names.

How many colors are there in R?

R has 657 built in color names To see a list of names: colors() These colors are displayed on P. 3. Finding a good color scheme for presenting data can be challenging.


2 Answers

RColorBrewer, as mentioned by deinst, is very useful -- even though it was designed for maps rather than line charts.

A number of other packages offer help with palettes:

  • gplots has colorpanel(), rich.colors(), ...
  • hcl-colors
  • colorRamps
  • colorspace
  • caTools
  • caTools
  • ...

as can be seen from a quick query on 'palette' at rseek.org.

like image 161
Dirk Eddelbuettel Avatar answered Sep 24 '22 07:09

Dirk Eddelbuettel


The easiest way to generate a palette is using generic functions from the basic grDevices package:

rainbow()
topo.colors()
terrain.colors()
heat.colors()

These are useful if the desired number of colors doesn't exceed 7-8. The only necessary argument is the number of colors in palette.

There is also gray() function which can be used to generate various schades of gray.

Or you could do something like:

pal <- colorRampPalette(c("red", "blue", "plum"))
barplot(t(as.matrix(mydf)), beside=TRUE, col=pal(3))
like image 22
donshikin Avatar answered Sep 22 '22 07:09

donshikin