[R] [Summary] Color names

About this list Date view Thread view Subject view Author view Attachment view

From: Gabor Grothendieck (ggrothendieck@volcanomail.com)
Date: Sun 29 Jun 2003 - 16:10:50 EST


Message-id: <20030629061050.6C266ABE0@sitemail.everyone.net>

Thanks to those who took time to respond. Based on the functions
that were pointed out to me I have the following:

# colors.hex and colors.name convert color names to hex and visa versa

# note that each color has a unique hex code but each hex code may have
# more than one color

   colors.hex <- function( x=colors() ) {
           color.hex <- function(x) do.call( "rgb", as.list(col2rgb(x)/255) )
           sapply( x, color.hex )
           }

   colors.name <- function( x ) {
           color.name <- function( x ) colors()[ colors.hex() == x ]
           lapply( x, color.name )
           }

# For example,

   colors.hex( "red" )
   colors.hex( colors()[1:5] )

   colors.name( "#FF0000" )
   colors.name( rainbow(3) )
   colors.name( rainbow(7) ) # note: only first element has a name

# LL partitions all color names into equivalence classes w same hex code
# LL2 is similar but only has equivalence classes with more than one name

   LL <- by( colors(), colors.hex(), as.vector )
   LL2 <- LL[ lapply( LL, length ) > 1 ]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Tue 01 Jul 2003 - 09:12:09 EST