Named Colors in R

I spend too much time picking out colors for plots. R knows the names of 657 of them, but sometimes I don’t know if I’m in the mood for steelblue3 or steelblue4. I have this handy function in my .Rprofile file which takes a search string such as “blue” and returns a plot showing all colors with matching names.

plot.color.matches = function (col.search.str) {

	matches = colors()[grep(col.search.str, colors())]

	barplot(rep(1, length(matches)), col=matches, 
		pch=16, names=matches, las=2, cex.names=0.5, axes=FALSE)

}

You can call it with

plot.color.matches("blue")

or

plot.color.matches("gold")

or

plot.color.matches("salmon")

or

plot.color.matches("dark")

to see all matching colors side by side.

R Named Colors - Blues

darks

I’ve decided on “deepskyblue4″ for the current plot.