[R] hex2RGB back to hex not the same?

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Aug 28 22:30:12 CEST 2008


On Thu, Aug 28, 2008 at 1:07 PM, Aaron Mackey <ajmackey at gmail.com> wrote:
> Witness this oddity (to me):
>
>> rainbow_hcl(10)[1]
> [1] "#E18E9E"
>> d <- attributes(hex2RGB(rainbow_hcl(10)))$coords[1,]
>> rgb(d[1], d[2], d[3])
> [1] "#C54D5F"
>
> What happened?  FYI, this came up as I'm trying to reuse the RGB values I
> get from rainbow_hcl in a call to rgb() where I can also set alpha
> transparency levels ...

> d <- coords(hex2RGB("#E18E9E", gamma=NA))
> rgb(d[,1], d[,2], d[,3])
[1] "#E18E9E"

Another alternative is

> d <- col2rgb("#E18E9E") / 255
> rgb(d[1,], d[2,], d[3,])
[1] "#E18E9E"

-Deepayan



More information about the R-help mailing list