I am on the lookout for a function that reduces the saturation of a given colour palette by a certain amount. E.g. imagine I have the palette
library(colorRamps)
col.palette=colorRampPalette(rainbow(13),interpolate ="spline")(1000)
pie(rep(1,1000), col=col.palette,lty=0,labels=NA)
Is there any function out there that could work on this col.palette
colour vector, and reduce the saturation by a certain amount, or allow the brightness and contrast to be changed? (I am trying to achieve a rainbow palette with less saturation and smoother transitions than the standard one)
EDIT: also just discovered function muted
in package scales
that more or less does what I want :
http://www.inside-r.org/packages/cran/scales/docs/muted
as well as rainbow_hcl
in package colorspace
mentioned by Josh O'Brien below, which was the kind of more muted and equal intensity rainbow I was looking for :
http://www.inside-r.org/packages/cran/colorspace/docs/rainbow_hcl :
library(colorspace)
pie(rep(1,1000), col=rainbow_hcl(1000,c=100,l=60),lty=0,labels=NA)
Reducing the saturation drains the color away, leaving just the grayscale component. Taupe and mauve are low-saturation colors because they are quite neutral, with just a touch of color. Apple red and banana yellow are high-saturation colors.
Saturation. Saturation describes a color's brilliance or intensity. A saturated color is very vibrant and intense, while a dull color is often described as desaturated. Here's an example: The red on the left is bright and saturated, while the red on the right is less intense and desaturated.
Saturation. The saturation of a color is determined by a combination of light intensity and how much it is distributed across the spectrum of different wavelengths. The purest (most saturated) color is achieved by using just one wavelength at a high intensity, such as in laser light.
The more saturated a color is, the brighter and more intense it looks. The less saturated a color is, the duller and gloomier it looks. The other name of color saturation is the color intensity or chroma.
Here's a function that will desaturate a vector of input colors by a specified proportion:
library(colorspace) ## hsv colorspace manipulations
library(RColorBrewer) ## For some example colors
## Function for desaturating colors by specified proportion
desat <- function(cols, sat=0.5) {
X <- diag(c(1, sat, 1)) %*% rgb2hsv(col2rgb(cols))
hsv(X[1,], X[2,], X[3,])
}
And here's an example of what it looks like in action:
## Utility function for plotting color palettes,
## (from vignette("hcl-colors"))
pal <- function(col, border = "light gray", ...) {
n <- length(col)
plot(0, 0, type="n", xlim = c(0, 1), ylim = c(0, 1),
axes = FALSE, xlab = "", ylab = "", ...)
rect(0:(n-1)/n, 0, 1:n/n, 1, col = col, border = border)
}
## Some example colors
cc <- brewer.pal(9, 'Set1')
cc75 <- desat(cc, 0.75)
cc50 <- desat(cc, 0.50)
cc25 <- desat(cc, 0.25)
## Plot 'em
par(mfcol = c(4,1), mar = c(0,0,0,0))
pal(cc)
pal(cc75)
pal(cc50)
pal(cc25)
Here is another approach. In rainbow()
, you can use two more parameters (i.e, s and v). s is for saturation. If you play with these two parameters you would be able to get what you want.
col.palette=colorRampPalette(rainbow(13, s = 1, v = 0.8),interpolate = "spline")(1000)
pie(rep(1,1000), col=col.palette,lty=0,labels=NA)
col.palette=colorRampPalette(rainbow(13, s = 0.6, v = 1),interpolate = "spline")(1000)
pie(rep(1,1000), col=col.palette,lty=0,labels=NA)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With