# Colors in R

## Colors in R

We get the list of all named colors in R using the command

```> help(colors)
> colors()```

A colored list of colors is available on the WWW.

The basic commands for dealing with colors are extended by the package colorspace.

Different color definitions can be found at http://colors.bravo9.com/ , http://en.wikipedia.org/wiki/List_of_colors and sites of color producers such as Crayola (colors) or Caran d'Ache (colors).

## Palettes of distinct colors for nominal data

Suppose that we produced a clustering of given territorial units. We would like to display it on the corresponding map so that the units belonging to different clusters can be easily seen.

This leads to a problem of constructing of a palette of colors as distinct as possible. The standard solution in R is provided by RColorBrewer

```> library(RColorBrewer)
> display.brewer.all(type="qual")```

Ware recommends the six opponent-channel colors (red, green, yellow, blue, black, white) followed by six other distinct colors (pink, cyan, gray, orange, brown, and purple).

But which palette to use if the number of clusters is over 12 ? The rainbow colors are too similar.

```> library(graphics)
> par(mar=c(1,1,1,0)+0.1)
> ware <- c("red","green","yellow","blue","black","white","pink","cyan","gray","orange","brown","purple")
> pie(rep(1,12), col=ware)
> pie(rep(1,24), col=rainbow(24))```

## Alphabet colors

An interesting solution for up to 26 colors was proposed by Paul Green-Armytage in his paper A Colour Alphabet and the Limits of Colour Coding.

His solution was inspired by the palette of 22 distinct colors proposed in 1965 by Kenneth Kelly.

The initial color alphabet was

and its revised final version

The final version has the property that the corresponding letter is also the first letter in the color's name.

```alphabet <- c(
rgb(255,204,153,maxColorValue=255,names="Honeydew"),
rgb( 94,241,242,maxColorValue=255,names="Sky"),
rgb(224,255,102,maxColorValue=255,names="Uranium"),
rgb(255,255,128,maxColorValue=255,names="Xanthin"),
rgb(240,160,255,maxColorValue=255,names="Amethyst"),
rgb(255,225,  0,maxColorValue=255,names="Yellow"),
rgb(255,168,187,maxColorValue=255,names="Pink"),
rgb(157,204,  0,maxColorValue=255,names="Lime"),
rgb(255,164,  5,maxColorValue=255,names="Orpiment"),
rgb( 43,206, 72,maxColorValue=255,names="Green"),
rgb(194,  0,136,maxColorValue=255,names="Mallow"),
rgb(255,  0, 16,maxColorValue=255,names="Red"),
rgb(  0,153,143,maxColorValue=255,names="Turquoise"),
rgb(116, 10,255,maxColorValue=255,names="Violet"),
rgb(255, 80,  5,maxColorValue=255,names="Zinnia"),
rgb(  0,117,220,maxColorValue=255,names="Blue"),
rgb(128,128,128,maxColorValue=255,names="Iron"),
rgb(153, 63,  0,maxColorValue=255,names="Caramel"),
rgb(143,124,  0,maxColorValue=255,names="Khaki"),
rgb( 66,102,  0,maxColorValue=255,names="Quagmire"),
rgb(153,  0,  0,maxColorValue=255,names="Wine"),
rgb(  0, 92, 49,maxColorValue=255,names="Forest"),
rgb(  0, 51,128,maxColorValue=255,names="Navy"),
rgb( 76,  0, 92,maxColorValue=255,names="Damson"),
rgb( 25, 25, 25,maxColorValue=255,names="Ebony"),
rgb(255,255,255,maxColorValue=255,names="White"))```
```> n <- length(alphabet)
> pie(rep(1,n),col=alphabet)```

## Optimization approach

Chris Glasbey with his collaborators proposed in their paper Colour displays for categorical images an optimization approach to determine a palette with most distinct colors.

Similar approach was presented also in http://www.ics.uci.edu/~goodrich/pubs/color.pdf .

## To do

### Optimization

14.8.2011 Problem: ali se da narediti boljšo optimizacijo?

`pretvorba RGB -> LAB `

## Colors

```> relc <- c("lightpink","yellow","orange","olivedrab3","steelblue3","lightskyblue1",
+ "darkorchid","tomato","bisque3","springgreen3","darkgoldenrod","gray75")
> library(graphics)
> par(mar=c(1,1,1,0)+0.1)
> pie(rep(1,12), col=relc)
> relc <- c("lightpink","yellow","orange","olivedrab4","steelblue3","lightskyblue1",
+ "darkorchid","firebrick1","chartreuse","springgreen3","darkgoldenrod","gray75")
> pie(rep(1,12), col=relc)```

## Colors 2

```> d <- c(
+ 255,0,0   ,
+ 210,150,12 ,
+ 125,175,0  ,
+ 117,0,255  ,
+ 160,0,125  ,
+ 29,100,255 ,
+ 0,255,233  ,
+ 73,255,100 ,
+ 100,146,125,
+ 255,219,0  )
> D <- matrix(d,ncol=3,byrow=TRUE)
> cd <- rgb(D,maxColorValue=255)
> pie(rep(1,10), col=cd)
> cb <- c( "#FF0000C8", "#D2960CC8", "#7DAF00C8", "#7500FFC8", "#A0007DC8",
+          "#1D64FFC8", "#00FFE9C8", "#49FF64C8", "#64927DC8", "#FFDB00C8" )
> pie(rep(1,10), col=cb)```