From ggrothendieck at myway.com  Wed Oct 29 14:48:52 2003
From: ggrothendieck at myway.com (Gabor Grothendieck)
Date: Wed Oct 29 14:48:49 2003
Subject: [Rd] Wishlist: user-specified color names for palette() (PR#4836)
Message-ID: <20031029134852.91150396D@xmxpita.myway.com>



Provided you are willing to only use colors in the vector returned
by colors() then this function would do it for you:


colors.names <- function( x ) { 
   color.name <- function( x ) 
      ifelse(substr(x,1,1) == "#", colors()[ match( x, colors.hex() ) ], x )
   z <- sapply( x, color.name ) 
   ifelse(is.na(z), x, z)
}

where colors.hex is defined here:

   http://maths.newcastle.edu.au/~rking/R/help/03a/7417.html


e.g.

colors.names( c("red", "#FF00FF", "blue") )

---

To: <r-devel@stat.math.ethz.ch> 
Cc: <R-bugs@biostat.ku.dk> 
Subject: [Rd] Wishlist: user-specified color names for palette() (PR#4836) 

 
 
Full_Name: Hsiu-Khuern Tang
Version: 1.8.0
OS: GNU/Linux (Debian unstable)
Submission from: (NULL) (156.153.255.243)


Hi,

I use palette(rgb(red=..., green=..., blue=..., names=mycolors)) to define my
own color palette. After doing this, the names `mycolors' are not stored in
palette() anymore, so that palette() returns a mix of built-in color names and
RGB values.

Eg:
> palette()
[1] "black" "#EAA200" "#FF6633" "gray60"

I wish that palette() would return a _named vector_ like this:

> palette()
black orange tomato gray 
"#000000" "#EAA200" "#FF6633" "#999999" 

One application:

I want to specify colors by name, where the names returned by palette() are
searched first. If there is a match, the corresponding RGB value is used;
otherwise the built-in R color is used.

Best,
Hsiu-Khuern Tang.

______________________________________________

  
 

        

_______________________________________________
No banners. No pop-ups. No kidding.
Introducing My Way - http://www.myway.com


[Rd] Wishlist: user-specified color names for palette() (PR#4836)
Gabor Grothendieck