There are a few packages for handling colour mathematically in R -
“Create colour-scheme functions for fine control of colours driven by your data.”
“Functions for computing coordinate conversions between colorspaces.”
“Builds gradient color maps”