Friday, November 18, 2005

Paint with all the colours of the wind


Here's a function I wrote in R to help me pick colours when producing beautiful graphs:

showcol <- function(col) {
co <- colors()[grep(col,colors())]
thickness <- floor(400/length(co))
par(mar=c(1,8,1,1))
par(las=1)
plot(0,0,type="n",xlim=c(0,1),
ylim=c(1,length(co)),axes=FALSE,
xlab="",ylab="")
mtext(co,line=1,side=2,at=1:length(co),cex=0.7)
for (i in 1:length(co)) {
segments(0,i,1,i,col=co[i],lwd=thickness)
}
}

To produce the figure at right, you simply call

showcol("brown")

Some of those don't look all that brown to me ...

P.S. I couldn't figure out how to get Blogger to keep my indentation in the code above, but at least you can copy and paste this directly into R and it works. And I got to learn all about CSS.
Bookmark and Share

0 Comments:

Post a Comment

<< Home