Stuff I Routinely Forget How to Do

A surprisingly important hunk of my bioinformatic skill set consists of Googling for error messages and implementing whatever fix the, say, StackOverflow posters suggested. I’ve collected the wisdom gleaned from such forums, man pages, and other programmers into this (newly relocated and expanded) document on GitHub: Stuff I Routinely Forget How to Do. I’m sure I’ll refer to it often and hopefully someone else will find it useful.

Elephant

(Elephant photo by Flickr user guido da rozze.)

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.