[R] "rgb()" problem

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


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