Converting between colour spaces using R
| updated
As an example, let’s convert one of the ColorBrewer palettes to HSV.
First, set up a minimal R environment. Then install the RColorBrewer package:
sudo apt install r-cran-rcolorbrewer
To look up the available functionality in an interactive R session:
> help(colorspaces)
> apropos("hsv")
> help(rgb2hsv)
See which palettes are available:
> require("RColorBrewer")
> help(brewer.pal)
> brewer.pal.info
And convert it to RGB and then to HSV:
> p <- brewer.pal(4, "Set2")
> rgb2hsv(col2rgb(p))
[,1] [,2] [,3] [,4]
h 0.45 0.05 0.62 0.90
s 0.47 0.61 0.31 0.40
v 0.76 0.99 0.80 0.91
Note: The Oklab colour space has better visual properties than HSV and is now generally available for use in CSS stylesheets.