OCHA-DAP / gghdx

HDX Theme, Scales, and Other Conveniences for 'ggplot2'
GNU General Public License v3.0
5 stars 0 forks source link

Feature Request - `RColorBrewer::brewer.pal()` equivalent #10

Closed zackarno closed 1 year ago

zackarno commented 2 years ago

RColorBrewer::brewer.pal() is one of the palette functions I tend to use most.

Would be cool to have an equivalent where you just specify n and palette name and the hex codes are returned. I see hdx_pal(), but doesn't look like it's designed the same way.

Also an accompanying equivalent to RColorBrewer::display.brewer.all() would be awesome eventually

caldwellst commented 2 years ago

So, we do have the functionality of RColorBrewer::brewer.pal(). I constructed hdx_pal(), and the others shade specific ones hdx_pal_mint(), hdx_pal_tomato() and hdx_pal_sapphire() the same way that ggthemes constructed the palette functions. That is, they are a constructor function that once run, returns a palette that can then be used with n. Try hdx_pal_mint()(3) for instance, or hdx_pal()(6).

Now, I"m trying to remember what the advantage was to constructing it in this manner rather than directly just having a the brewer.pal() setup. I can't remember, so maybe we can investigate in time and make a decision to switch to the direct palette format. I don't think that would necessarily be a problem at all and might make it easier for the user.

Agreed on the display.brewer.all() format.

zackarno commented 1 year ago

I didn't realize they worked like this, good to know - should be sweet, but also down to test out different options.

zackarno commented 1 year ago

hmmm, that example didn't seem to work. Any suggestions?

gghdx::hdx_pal_mint()[1]
#> Error in gghdx::hdx_pal_mint()[1]: object of type 'closure' is not subsettable

Created on 2022-12-08 by the reprex package (v2.0.1)

zackarno commented 1 year ago

hmmm, that example didn't seem to work. Any suggestions?

gghdx::hdx_pal_mint()[1]
#> Error in gghdx::hdx_pal_mint()[1]: object of type 'closure' is not subsettable

Created on 2022-12-08 by the reprex package (v2.0.1)

oh my bad I use square brackets which was wrong.... gghdx::hdx_pal_mint()(1) does work

caldwellst commented 1 year ago

Yeah, it's a function generator so gotta call the next one as a function!

caldwellst commented 1 year ago

So, just revisiting some things, and note that hdx_pal() as a generator function (and all the other hdx_pal...() functions) are required for the scale_fill_...() and scale_color_...() functions. Hence why constructed that way.

However, will look into recreating a brewer.display.all() function soon.

caldwellst commented 1 year ago

Fixed in #13