简体   繁体   English

计算R中可区分的调色板

[英]Calculate distinguishable color palette in R

I am using R to create a plot that contains 20 distinct groups, and I would like to color each of them differently. 我正在使用R创建一个包含20个不同组的图,我想以不同的方式为每个组着色。 I am also familiar with Matlab and when working with that program I have found that "distinguishable_colors" matlab file worked best for distinguishing different colors 1 . 我也熟悉Matlab,在使用该程序时,我发现“distinguishedishable_colors”matlab文件最适合区分不同的颜色1 I have looked at the "rainbow", "rainbow_hcl", and "brewer" palettes, but none of them look as good as "distinguishable_colors.mat". 我看过“rainbow”,“rainbow_hcl”和“brewer”调色板,但它们都没有“distinguishedishable_colors.mat”那么好看。 I am wondering if anyone knows of a function in R that will create the same palette as the "distinguishable_colors.mat" matlab function? 我想知道是否有人知道R中的一个函数将创建与“distinguishedishable_colors.mat”matlab函数相同的调色板?

That function in MatLab seems to iteratively search over RBG space for sets of color which are maximally different from each other. MatLab中的该函数似乎在RBG空间上迭代地搜索颜色组,这些颜色组彼此最大不同。 I don't know of such a thing in R, but we can come pretty close. 我不知道R中有这样的事情,但我们可以非常接近。

We can find a color palette of a few colors which suits our needs (perhaps using http://colorbrewer2.org/ ) and use those seed color to create a colorRampPalette for any number of colors. 我们可以找到适合我们需求的几种颜色的调色板(可能使用http://colorbrewer2.org/ )并使用这些种子颜色为任意数量的颜色创建colorRampPalette

pal<-colorRampPalette(c('#e41a1c','#377eb8','#4daf4a','#984ea3','#ff7f00'))
N=10
plot(rnorm(N),rnorm(N),pch=16,col=pal(N),cex=3)

The R package Polychrome provides tools for qualitative palettes with many (20 or more) colors. R package Polychrome提供多种(20种或更多)颜色的定性调色板工具。 It comes with two vignettes giving the provided palettes and tools for creating palettes . 它附带两个小插图, 提供用于创建调色板的 调色板和工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM