简体   繁体   中英

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. 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 . I have looked at the "rainbow", "rainbow_hcl", and "brewer" palettes, but none of them look as good as "distinguishable_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?

That function in MatLab seems to iteratively search over RBG space for sets of color which are maximally different from each other. I don't know of such a thing in R, but we can come pretty close.

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.

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. It comes with two vignettes giving the provided palettes and tools for creating palettes .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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