Tuesday, September 2, 2008

Some R color palettes

Once working on the trajectory plotting procedure I got curious about colors to use in my plots. I did a little research about what are common palettes used in R and there they are:

R color palettes

The R code snippet:

YlOrBr <- c("#FFFFD4", "#FED98E", "#FE9929", "#D95F0E", "#993404")
YlOrBr.Lab <- colorRampPalette(YlOrBr, space = "Lab")
YlOrBr.Lab.bias <- colorRampPalette(YlOrBr, space = "Lab", bias=0.5)

jet.colors <-
colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan",
"#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))

rgb.palette <- colorRampPalette(c("blue", "orange", "red"),
space = "rgb")
Lab.palette <- colorRampPalette(c("blue", "orange", "red"),
space = "Lab")

demo.pal <-
function(n, border = if (n<32) "light gray" else NA,
main = paste("color palettes; n=",n),
ch.col = c("YlOrBr.Lab.bias(n)", "YlOrBr.Lab(n)",
"heat.colors(n)", "terrain.colors(n)",
"cm.colors(n)", "topo.colors(n)",
"rainbow(n, start=.7, end=.1)", "jet.colors(n)",
"rgb.palette(n)", "Lab.palette(n)"))
{
nt <- length(ch.col)
i <- 1:n; j <- n / nt; d <- j/6; dy <- 2.2*d
plot(i,i+d, type="n", yaxt="n", ylab="", main=main)
for (k in 1:nt) {
rect(i-.5, (k-1)*j+ dy, i+.4, k*j,
col = eval(parse(text=ch.col[k])), border = border)
text(2*j, k * j +dy/4, ch.col[k])
}
}
n <- if(.Device == "postscript") 64 else 18
# Since for screen, larger n may give color allocation problem
demo.pal(n)

No comments: