I’m converting colours to HSV in order to remap the colour. In fact, I am generating a gradient of grey colours with gray.colors
:
(mydata <- 1 : 10) # For exposition only
cols <- gray.colors(max(mydata))
However, what I actually want is a gradient of white–red instead of white–black. A bit of fiddling with the colour picker has convinced me that for this it should be enough to swap the value and saturation on the greyscale colours and then set the value to 1 (the hue of 0 already corresponds to red).
Nothing’s easier:
hsvc <-rgb2hsv(col2rgb(cols))
hsvc['s', ] <- hsvc['v', ]
hsvc['v', ] <- 1
However, in order to plot these values I now need to convert them back to R colour values. I don’t seem to be able to do this because of a missing hsv2col
. Sure, there’s hsv
which purports to do this but you cannot call it with the value of hsvc
above – not even with a single column:
hsv(hsvc[, 1]) # plots *three* (wrong) colour values instead of one
And R cannot use the HSV values directly:
plot(1, 1, pch = 20, col = cols[1]) # Works, grey dot
plot(1, 1, pch = 20, col = hsvc[, 1]) # Nothing plotted
How do I get R-usable colour values back from the matrix of HSV values?