[R] Recipe: Print a Color Sampler

From: Ana Nelson <nelson.ana_at_gmail.com>
Date: Sun 22 Oct 2006 - 11:51:19 GMT


I wrote this to help me choose a suitable plot color. You can set the value of pch to whichever type of point you are using in your plot, and then you can see what the various colors will look like. When this plot it stretched to A4/Letter landscape it prints quite nicely, even though it will look very bunched up initially. I have only used this on my own machine which runs Apple OSX 10.4.

I included a getColorName() convenience function to retrieve the name of the color from its position in the colors() array which is printed next to the dot in the plot.

printColorSampler <- function() {

     i <- 1
     pch <- 20
     l <- length(colors())
     k <- ceiling(sqrt(l))

     plot(floor(i/k), i %% k, pch=pch, col=colors()[i], xlim=c(0,  
k*2), ylim=c(0, k), axes=FALSE, xlab="", ylab="")
     for (i in 2:length(colors())) {
     	x <- floor(i/k)*2
     	y <- i %% k
     	col=colors()[i]
     	points(x, y, pch=pch, col=col)
     	text(x+0.5, y+0.2, i, col=col, cex=0.7)
     }

}

getColorName <- function(colorNumber) {

     colors()[colorNumber]
}



R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun Oct 22 21:56:40 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 22 Oct 2006 - 13:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.