[R] "rgb()" problem

Röver, Christian chr|@t|@n@roever @end|ng |rom med@un|-goett|ngen@de
Fri Jul 26 10:51:02 CEST 2019


Sorry, I meanwhile realized -- specifying

  rgb(255, 128, 128, alpha=0.5*255, maxColorValue=255)

and

  rgb(1.0, 0.5, 0.5, alpha=0.5, maxColorValue=1)

gives you (virtually) identical results, i.e., you need to also specify
the "alpha" parameter in the range given by the "maxColorValue"
argument.

Sorry for the confusion,

Christian


On Fri, 2019-07-26 at 10:27 +0200, Christian Röver wrote:
> Hi,
> 
> I experienced a problem with the "rgb()" function.
> These two calls should (and do) return identical results:
> 
>   rgb(255, 128, 128, maxColorValue=255)
>   rgb(1.0, 0.5, 0.5, maxColorValue=1)
> 
> However, when I specify a non-default "alpha" channel (a
> "transparent"
> colour), I get differing results:
> 
>   rgb(255, 128, 128, alpha=0.5, maxColorValue=255)
>   rgb(1.0, 0.5, 0.5, alpha=0.5, maxColorValue=1)
> 
> where only the latter version seems to yield the actually intended
> result.
> 
> Is this a bug?
> 
> 
> You can check the actual colours' appearance this way:
> 
>   barplot(3:5, col=rgb(255, 128, 128, maxColorValue=255))
>   barplot(3:5, col=rgb(1.0, 0.5, 0.5, maxColorValue=1))
> 
>   barplot(3:5, col=rgb(255, 128, 128, alpha=0.5, maxColorValue=255))
>   barplot(3:5, col=rgb(1.0, 0.5, 0.5, alpha=0.5, maxColorValue=1))
> 
> The apparently buggy version in this case seems to return white
> instead
> of red.
> 
> 
> Thanks,
> 
> Christian


More information about the R-help mailing list