PlotThemes.jl icon indicating copy to clipboard operation
PlotThemes.jl copied to clipboard

Adding R's color brewer pallet

Open ValentinKaisermayer opened this issue 5 years ago • 13 comments

Would you consider adding the R color brewer pallete

e.g. dark2 pallete

dark2 = [
 RGB(([ 27, 158, 119]/255)...),
 RGB(([217,  95,   2]/255)...),
 RGB(([117, 112, 179]/255)...),
 RGB(([231,  41, 138]/255)...),
 RGB(([102, 166,  30]/255)...),
 RGB(([230, 171,   2]/255)...),
 RGB(([166, 118,  29]/255)...),
 RGB(([102, 102, 102]/255)...)
 ]

image

see Github source

ValentinKaisermayer avatar Oct 07 '19 09:10 ValentinKaisermayer

The colorbrewer palettes (which have nothing to do with R) are added. dark2 has been one of the few that was kept out for some time - but this open PR adds them https://github.com/JuliaPlots/PlotUtils.jl/pull/67

mkborregaard avatar Oct 07 '19 09:10 mkborregaard

see also https://docs.juliaplots.org/latest/colors/#colorschemes

mkborregaard avatar Oct 07 '19 09:10 mkborregaard

Thank you!

ValentinKaisermayer avatar Oct 07 '19 10:10 ValentinKaisermayer

This does not really work:

using Plots, PlotThemes
clibrary(:colorbrewer)
plot(rand(5, 100)', lw=2, palette=:Dark2)

image

The automatically chosen colors are too similar and are hard to distinguish.

ValentinKaisermayer avatar Oct 07 '19 11:10 ValentinKaisermayer

Especially 2, 3 and 4 in the above plot.

ValentinKaisermayer avatar Oct 07 '19 11:10 ValentinKaisermayer

Did you check out that Pull Request I linked?

mkborregaard avatar Oct 07 '19 11:10 mkborregaard

Oh I see it got merged. So this is on master? The colors do look a little off.

mkborregaard avatar Oct 07 '19 11:10 mkborregaard

~~palette = palette(:Dark2) works, but IMO palette = :Dark2 should also. Not sure what's the issue there, maybe a call to distinguishable_colors or something.~~

EDIT: No it does not, it just uses the default palette, sorry ...

daschw avatar Oct 07 '19 12:10 daschw

The problem seems to be in get_color_palette which is called by plot when the palette argument is supplied.

The following code would produce the correct color palette.

grad = cgrad(:Dark2)
RGBA{Float64}[grad[z] for z in 1:numcolors]

ValentinKaisermayer avatar Oct 07 '19 14:10 ValentinKaisermayer

zrng = get_zvalues(numcolors) produces a weird, unordered list of values between 0 and 1 which may be beneficial if the underlying cgrad is ordered in some sense. But in this case it is not.

ValentinKaisermayer avatar Oct 07 '19 14:10 ValentinKaisermayer

Yes, we had some discussion about how to best add the categorical palettes, as they are something different from color gradients. We ended up agreeing that we could just include them and it would be fine. Looks like that wasn't correct.

mkborregaard avatar Oct 08 '19 06:10 mkborregaard

So, do you think we need a type different from ColorGradient for categorical palettes?

daschw avatar Oct 08 '19 07:10 daschw

I think distinguishing between them could be a possibility yes. But a little unsure of the repercussions

mkborregaard avatar Oct 08 '19 07:10 mkborregaard