[R] What are the color's name in heat.color(5)

Eik Vettorazzi E.Vettorazzi at uke.de
Wed Mar 28 17:23:10 CEST 2012


Hi,
just one more note, col2rgb works for color codes as well:

(HC.m <- col2rgb(heat.colors(5)))

and to convert named colors to color codes, something like

tabl<-apply(col2rgb(colors()),2,function(x)do.call(rgb,c(as.list(x),alpha=255,maxColorValue=255)))
names(tabl)<-colors()
tabl

should work.

cheers

Am 28.03.2012 15:51, schrieb David Winsemius:
> 
> On Mar 28, 2012, at 9:08 AM, Kevin Wright wrote:
> 
>> They have hex RGB values instead of names:
>>
>> R> heat.colors(5)
> 
>> [1] "#FF0000FF" "#FF5500FF" "#FFAA00FF" "#FFFF00FF" "#FFFF80FF"
>>
>> Kevin
> 
> The first one is the same as 'red' as can be seen by parsing the RGB
> values above:
> 
>> col2rgb("red")
>       [,1]
> red    255
> green    0
> blue     0
> 
> HC.m < matrix( c( strtoi( substr(heat.colors(5), 2,3), 16L),
> strtoi(substr(heat.colors(5), 4,5), 16L), strtoi(substr(heat.colors(5),
> 6,7), 16L) ), nrow=3, byrow=TRUE)
> HC.m
>      [,1] [,2] [,3] [,4] [,5]
> [1,]  255  255  255  255  255
> [2,]    0   85  170  255  255
> [3,]    0    0    0    0  128
> 
> One of the others 'yellow' is also in named colors:
> 
>> which( apply(col2rgb(colors()) , 2 , function(x) all( x ==
> c(HC.m[,2]))) )
> integer(0)
>> which( apply(col2rgb(colors()) , 2 , function(x) all( x ==
> c(HC.m[,3]))) )
> integer(0)
>> which( apply(col2rgb(colors()) , 2 , function(x) all( x ==
> c(HC.m[,1]))) )
> [1] 552 553
>> which( apply(col2rgb(colors()) , 2 , function(x) all( x ==
> c(HC.m[,4]))) )
> [1] 652 653
>> which( apply(col2rgb(colors()) , 2 , function(x) all( x ==
> c(HC.m[,5]))) )
> integer(0)
> 
>> colors()[552: 553]
> [1] "red"  "red1"
> 
>> colors()[652:653]
> [1] "yellow"  "yellow1"
> 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 



More information about the R-help mailing list