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?

Melinda
  • 107
  • 1
  • 6
  • 6
    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. – Maurits Evers May 13 '18 at 22:17
  • Perhaps relevant is the following post: [How to generate a number of most distinctive colours in R](https://stackoverflow.com/questions/15282580/how-to-generate-a-number-of-most-distinctive-colors-in-r) – Maurits Evers May 13 '18 at 22:19
  • 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). – Melinda May 14 '18 at 13:42

1 Answers1

6

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

Tung
  • 26,371
  • 7
  • 91
  • 115
  • Related: https://stackoverflow.com/questions/57153428/r-plot-color-combinations-that-are-colorblind-accessible/57157075#57157075 – Tung May 29 '20 at 17:02
  • https://stackoverflow.com/questions/37482977/what-is-a-good-palette-for-divergent-colors-in-r-or-can-viridis-and-magma-b/52812120#52812120 – Tung May 29 '20 at 17:03