R colors - many distinctive colors that are still pretty

浪尽此生 提交于 2019-12-10 23:24:33

问题


I am curious if you have some tips on colour-brewing in R, for many distinctive colours, in a way that the graph is still good-looking.

I need a fair amount of distinctive colours (24 at least, probably will need even more, ~50) for stacked area plots (so not heatmaps, gradual colours would not work). I came across viridis, that has really pretty palettes, which also work for colourblind people. Unfortunatelly those do not have enough colours to still be distinguishable on my plots.

I looked into other packages/palettes too, after spending some time on google (this post was particularly cool: How to generate a number of most distinctive colors in R?), but did not find anything that had enough colours AND still looked good.

How do you make a graph good looking when 24+ colours are needed?


回答1:


You can try either randomcoloR (up to 40 distinct colors) or pals (up to 26 colors).

# k: number of colors (>= 1). May be ineffective for k > 40.
library(randomcoloR)
nColor <- 40
myColor <- randomcoloR::distinctColorPalette(k = 40)
pie(rep(1, nColor), col = myColor)

# https://cran.r-project.org/web/packages/pals/vignettes/pals_examples.html
library(pals)
labs = c('alphabet', 'alphabet2', 'glasbey', 'kelly', 'polychrome')
op = par(mar = c(0, 5, 3, 1))
pal.bands(alphabet(), alphabet2(), glasbey(), kelly(), polychrome(), 
          labels = labs, show.names = FALSE)

Created on 2018-05-13 by the reprex package (v0.2.0).



来源:https://stackoverflow.com/questions/50321000/r-colors-many-distinctive-colors-that-are-still-pretty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!