[R] Creating a vector of colours that are as different from one another as possible

Petr Pikal petr.pikal at precheza.cz
Tue Dec 21 14:37:15 CET 2004



On 21 Dec 2004 at 11:05, michael watson (IAH-C) wrote:

> Hi
> 
> I want to create a vector of colors that are as different from one
> another as possible.  ?rainbow states "Conceptually, all of these
> functions actually use (parts of) a line cut out of the 3-dimensional
> color space...".  This suggests to me that the resulting colors are
> all placed on this "line" and are equi-distant along it.  The
> resulting color palette is a range of colours where adjacent colours
> are actually quite similar, especially when n (the number of colours)
> is high.
> 
> Conceptually I guess what I want is colors from a 3D polygon in 3D
> colour space, where the number of vertices in the polygon is n,
> resulting in a color palette where the colors are all quite different
> from one another.  Is this possible or am I talking crap? (I've only
> had one coffee this morning)

Hi Micheal

With increased number of colors you always end with neighbour 
colors quite similar. If I understand the rainbow function correctly 
it sets saturation to 1 (maximum) value to 1 (maximum) and divide 
the third component hue to equally spaced intervals to get the most 
different colours from given range of hues.

You can also experiment with hsv() function

> plot(1:11, col = hsv(h = seq(0,1,.1), s=1, v=0)) #all black
> plot(1:11, col = hsv(h = seq(0,1,.1), s=1, v=1)) # different colours

You can imagine hue as a circle from 0 to 360 and if you want to 
have neighbouring colours to be the most different you have to 
choose them from oposit parts of a circle e.g. 0,180 or 90,270.

So

barvy<-rainbow(12)
vyber<-c(1,7,3,9,5,11,2,8,4,10,6,12)
plot(1:12,col=rainbow(12)[vyber])

will give you a sequence of 12 colours which are by my opinion 
most different.

Cheers
Petr


> 
> Thanks in advance
> Mick
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list