[R] color palette for points, lines, text / interactive Rcolorpicker?

Greg Snow Greg.Snow at imail.org
Thu Jan 28 21:40:38 CET 2010


I don't know of any existing palettes that meet your conditions, but here are a couple of options for interactive exploration of colorsets (this is quick and dirty, there are probably some better orderings, base colors, etc.):

colpicker <- function( cols=colors() ) {
	n <- length(cols)
	nr <- ceiling(sqrt(n))
	nc <- ceiling( n/nr )

	imat <- matrix(c(seq_along(cols), rep(NA, nr*nc-n) ),
				ncol=nc, nrow=nr)

	image( seq.int(nr),seq.int(nc), imat, col=cols, xlab='', ylab='' )
	xy <- locator()

	cols[ imat[ cbind( round(xy$x), round(xy$y) ) ] ]
}

colpicker()


## another approach

library(TeachingDemos)

cols <- colors()
n <- length(cols)
par(xpd=TRUE)

# next line only works on windows
HWidentify( (1:n) %% 26, (1:n) %/% 26, label=cols, col=cols, pch=15, cex=2 )

# next line works on all platforms with tcltk
HTKidentify( (1:n) %% 26, (1:n) %/% 26, label=cols, col=cols, pch=15, cex=2 )


# reorder
cols.rgb <- col2rgb( cols )
d <- dist(t(cols.rgb))
clst <- hclust(d)

colpicker(cols[clst$order])
HWidentify( (1:n) %% 26, (1:n) %/% 26, label=cols[clst$order], col=cols[clst$order], pch=15, cex=2 )
## or HTKidentify

cols.hsv <- rgb2hsv( cols.rgb )
d2 <- dist(t(cols.hsv))
clst2 <- hclust(d2)

HWidentify( (1:n) %% 26, (1:n) %/% 26, label=cols[clst2$order], col=cols[clst2$order], pch=15, cex=2 )
## or HTKidentify

Hope this helps,
	

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Michael Friendly
> Sent: Thursday, January 28, 2010 8:38 AM
> To: R-Help
> Subject: [R] color palette for points, lines, text / interactive
> Rcolorpicker?
> 
> I'm looking for a scheme to generate a default color palette for
> plotting points, lines and text (on a white or transparent background)
> with from 2 to say 9 colors with the following constraints:
> - "red" is reserved for another purpose
> - colors should be highly distinct
> - avoid light colors (like "yellow"s)
> 
> In RColorBrewer, most of the schemes are designed for area fill rather
> than points and lines. The closest I can find
> for these needs is the Dark2 palette, e.g.,
> 
> library(RColorBrewer)
> display.brewer.pal(7,"Dark2")
> 
> I'm wondering if there is something else I can use.
> 
> On a related note, I wonder if there is something like an interactive
> color picker for R.  For example,
> http://research.stowers-institute.org/efg/R/Color/Chart/
> displays several charts of all R colors.  I'd like to find something
> that displays such a chart and uses
> identify() to select a set of tiles, whose colors() indices are
> returned
> by the function.
> 
> -Michael
> 
> --
> Michael Friendly     Email: friendly AT yorku DOT ca
> Professor, Psychology Dept.
> York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
> 4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
> Toronto, ONT  M3J 1P3 CANADA
> 
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list