R:降低调色板的色彩饱和度 [英] R: reducing colour saturation of a colour palette
问题描述
我正在寻找一个将给定调色板的饱和度降低一定量的函数。例如。想象我有调色板
library(colorRamps)
col.palette = colorRampPalette spline)(1000)
pie(rep(1,1000),col = col.palette,lty = 0,labels = NA)
有没有任何函数可以在这个 col.palette
颜色矢量上工作,并减少一定量的饱和度,或允许亮度和对比度是否改变? (我试图实现一个彩虹调色板,比标准的饱和度和更平滑的过渡。)
编辑:也刚刚发现的函数 muted
in package
scales
,或多或少地做我想要的:
http://www.inside-r.org/packages/cran/scales/docs/muted
以及Josh O'Brien提到的 colorspace
中的 rainbow_hcl
是更多的静音和同等强度的彩虹我正在寻找:
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)
这里有一个函数将按指定比例去除输入颜色向量的饱和度:
库(colorspace)## hsv颜色空间操作
库(RColorBrewer)##对于一些示例颜色
##用于按照指定比例去饱和颜色的函数
desatX←diag(c(1,sat,1))%*%rgb2hsv(col2rgb cols))
hsv(X [1,],X [2,],X [3,])
}
下面是一个例子:
##实用程序绘制调色板的函数
##(来自vignette(hcl-colors))
pal< - function(col,border =light grey,...){
n < - length(col)
plot(0,0,type =n,xlim = c(0,1),ylim = c(0,1),
axes = FALSE, xab =,ylab =,...)
rect(0:(n-1)/ n,0,1:n / n,1,col = col,border = border)
}
##一些示例颜色
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 ,1),mar = c(0,0,0,0))
pal(cc)
pal(cc75)
pal(cc50)
pal b $ b
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 packagescales
that more or less does what I want : http://www.inside-r.org/packages/cran/scales/docs/mutedas well as
rainbow_hcl
in packagecolorspace
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)
解决方案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)
这篇关于R:降低调色板的色彩饱和度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!