Re: [R] Recipe: Print a Color Sampler

From: Antonio, Fabio Di Narzo <antonio.fabio_at_gmail.com>
Date: Sun 22 Oct 2006 - 14:28:44 GMT

Really fine.
Should this go on the wiki?

Antonio.

2006/10/22, Gabor Grothendieck <ggrothendieck@gmail.com>:
> Here it is again corrected:
>
> getColorName <- function(colorNumber) colors()[colorNumber]
> printColorSampler <- function(n = 0) {
> i <- seq(colors())
> k <- ceiling(sqrt(length(i)))
> xy <- cbind(floor(i/k)*2, i %% k)
> plot(xy, type = "n", axes = FALSE, xlab = "", ylab = "")
> text(xy[,1]+.5, xy[,2]+.2, i, col = colors(), cex = 0.7)
> if (n > 0)
> colors()[identify(xy, n = n, labels = colors(), plot = FALSE)]
> }
> # test
> printColorSampler(0)
> printColorSampler(1)
>
>
> On 10/22/06, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> > I have removed the dots, vectorized it and changed the
> > argument to the number points to be identified (default 0):
> >
> > getColorName <- function(colorNumber) colors()[colorNumber]
> > printColorSampler <- function(n = 0) {
> > i <- seq(colors())
> > k <- ceiling(sqrt(length(i)))
> > xy <- cbind(floor(i/k)*2, i %% k)
> > plot(xy, type = "n", axes = FALSE, xlab = "", ylab = "")
> > text(x+.5, y+.2, i, col = colors(), cex = 0.7)
> > if (n > 0)
> > colors()[identify(xy, n = n, labels = colors(), plot = FALSE)]
> > }
> > # test
> > printColorSampler(0)
> > printColorSampler(1)
> >
> >
> >
> > On 10/22/06, Stefano Calza <calza@med.unibs.it> wrote:
> > > Thanks, might be very useful.
> > >
> > > I attached a slightly modified version that uses identify (whith an argument to choose if use it), to return the name of the colors on the panel. Left-click on the choosen colors, and right click to end.
> > >
> > > Stefano
> > >
> > >
> > > On Sun, Oct 22, 2006 at 12:51:19PM +0100, Ana Nelson wrote:
> > > <Ana>I wrote this to help me choose a suitable plot color. You can set the
> > > <Ana>value of pch to whichever type of point you are using in your plot,
> > > <Ana>and then you can see what the various colors will look like. When
> > > <Ana>this plot it stretched to A4/Letter landscape it prints quite nicely,
> > > <Ana>even though it will look very bunched up initially. I have only used
> > > <Ana>this on my own machine which runs Apple OSX 10.4.
> > > <Ana>
> > > <Ana>I included a getColorName() convenience function to retrieve the name
> > > <Ana>of the color from its position in the colors() array which is printed
> > > <Ana>next to the dot in the plot.
> > > <Ana>
> > > <Ana>printColorSampler <- function() {
> > > <Ana> i <- 1
> > > <Ana> pch <- 20
> > > <Ana> l <- length(colors())
> > > <Ana> k <- ceiling(sqrt(l))
> > > <Ana>
> > > <Ana> plot(floor(i/k), i %% k, pch=pch, col=colors()[i], xlim=c(0,
> > > <Ana>k*2), ylim=c(0, k), axes=FALSE, xlab="", ylab="")
> > > <Ana>
> > > <Ana> for (i in 2:length(colors())) {
> > > <Ana> x <- floor(i/k)*2
> > > <Ana> y <- i %% k
> > > <Ana> col=colors()[i]
> > > <Ana> points(x, y, pch=pch, col=col)
> > > <Ana> text(x+0.5, y+0.2, i, col=col, cex=0.7)
> > > <Ana> }
> > > <Ana>}
> > > <Ana>
> > > <Ana>getColorName <- function(colorNumber) {
> > > <Ana> colors()[colorNumber]
> > > <Ana>}
> > > <Ana>
> > > <Ana>______________________________________________
> > > <Ana>R-help@stat.math.ethz.ch mailing list
> > > <Ana>https://stat.ethz.ch/mailman/listinfo/r-help
> > > <Ana>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > > <Ana>and provide commented, minimal, self-contained, reproducible code.
> > >
> > >
> > > ______________________________________________
> > > 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.
> > >
> > >
> > >
> > >
> >
>
> ______________________________________________
> 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.
>



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 Mon Oct 23 00:34:05 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 - 19:30:12 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.