Colors in R

Tian links to a document showing hundreds of shades of colors in R. I don’t think I would’ve listed them alphabetically, but it is convenient to see them all in one place. When picking out colors, don’t forget that they look different on the computer, projected onto a screen, and on paper.

3 thoughts on “Colors in R

  1. I have a function that shows all available colors and allows the user to click on the colors in order to identfy them. Of interest to you might be the sorting of the colors by HSV. It's far from perfect, but is better than alphabetical sorting.

    <pre>
    viewColors = function (ind = 1:length(colors()), identify = FALSE, sort = TRUE)
    {
    ind = setdiff(ind, grep("grey", colors()[ind]))
    if (sort) {
    indNames = colors()[ind]
    indRGB = col2rgb(indNames)
    indHSV = rgb2hsv(indRGB)
    hueOrder = order(indHSV[1, ], indHSV[2, ], indHSV[3,
    ])
    ind = ind[hueOrder]
    }
    indNames = colors()[ind]
    num = ceiling(sqrt(length(ind)))
    m = matrix(1:num^2, nrow = num)
    x = y = 1:num
    image(x, y, m, axes = F, col = c(colors()[ind], rep(colors()[1],
    num^2 – length(ind))), xlab = "", ylab = "")
    for (i in 1:length(ind) – 1) text(i%%num + 1, i%/%num + 1,
    ind[i + 1], cex = 0.6)
    if (identify) {
    title("Left-click to choose colors. Right-click to exit")
    cols = locator()
    x = round(cols$x)
    y = round(cols$y)
    ind = (y – 1) * num + x
    return(indNames[ind])
    }
    }
    </pre>

  2. These are the old X11 (unix windowing system) colors and are designed to look good on 256 color displays under X11. My experience is that the pdf rendering of these colors is slightly different from the X11 version, so the document as a pdf is somewhat interesting.

    I'm currently very interested in the colors near the back which come in intensity sequences, e.g., plum1, plum2, plum3, and plum4. I've taken to using them for barplots with ordered categories. There are several reasons for this:
    1) The graphics are still legible when printed on a B&W printer or copies on a B&W copier.
    2) Colorblind individuals (who are more common than you think) don't need to monkey with the colors to see the differences.
    3) They tend to look more subdued and less like a circus than using the standard eight color palatte.

    You can get similar effects by manipulating the S component in the HSV representations of a color.

Comments are closed.