R colors - many distinctive colors that are still pretty
Asked Answered
J

1

7

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?

Jere answered 13/5, 2018 at 21:59 Comment(3)
There is a reason why popular colour palettes (like the viridis or colorbrewer palettes) don't offer qualitative colour palettes with more than around 10 colours. It is nearly impossible for the eye to discern more colours! So I would strongly advice against using a 24+ colour palette. I can also guarantee that it will not "look good". Instead think about a different way of representing your data. You could use facets or other graph aesthetics to encode different features.Unilateral
Perhaps relevant is the following post: How to generate a number of most distinctive colours in RUnilateral
Yes, it makes sense. I am faceting the graphs, but the same variables appear on them. I was just advised to simply not assign colours to certain variables, because they don't really show up in the graph (their values are too little).Jere
V
7

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).

Volin answered 13/5, 2018 at 22:49 Comment(2)
Related: #57153928Volin
#37483477Volin

© 2022 - 2024 — McMap. All rights reserved.