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]
}
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 a 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.
-------------- parte successiva --------------
printColorSampler <- function(identify=TRUE) {
i <- 1
pch <- 20
l <- length(colors())
k <- ceiling(sqrt(l))
rec.coord <- data.frame(x=rep(NA,l),y=rep(NA,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="")
rec.coord[i,] <- c(floor(i/k),i %% k)
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)
rec.coord[i,] <- c(x,y)
}
if(identify)
{
wCol <- identify(rec.coord,labels=colors(),plot=FALSE)
return(colors()[wCol])
}
}
getColorName <- function(colorNumber) {
colors()[colorNumber]
}
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 at 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 at 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 at 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.
>
>
>
>
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 at 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 at 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 at 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 at 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.
> >
> >
> >
> >
>
Really fine. Should this go on the wiki? Antonio. 2006/10/22, Gabor Grothendieck <ggrothendieck a 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 a 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 a 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 a 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 a 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 a 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. >