paletteer icon indicating copy to clipboard operation
paletteer copied to clipboard

Feature request: centered palettes

Open wetlandscapes opened this issue 5 years ago • 0 comments

I was thinking it would be kind of neat to have an option in which colors were assigned from the middle of a palette, rather than from the left (i.e., direction = 1) or right (i.e., direction = -1).

For example say we wanted to use the following palette, but we only had three colors:

paletteer_d(ggthemes, hc_bg)
[1] "#d5e4eb" "#c3d6df" "#ed111a" "#ebebeb" "#c9c9c9"

Normally we'd do something like:

paletteer_d(ggthemes, hc_bg, n = 3) #or possibly paletteer_d(ggthemes, hc_bg, n = 3, direction = -1)
[1] "#d5e4eb" "#c3d6df" "#ed111a"

But what if we wanted to use the middle three colors? Usually I'd do something like:

paletteer_d(ggthemes, hc_bg)[c(2:4)]
[1] "#c3d6df" "#ed111a" "#ebebeb"

That's not terrible, but it can be inconvenient if dealing with a lot of changing group conditions.

What about an even number of groups? Could include an argument for starting from the left or the right of the middle color. Maybe even one for dropping the middle color. This could include similar logic for an even number of colors and an odd number of groups.

Thus, I could see a modification of the paletteer_* functions to include some new arguments:

paletteer_d(..., centered = c(TRUE, FALSE), side = c("left", "right", "middle"))
#Examples of functionality:
paletteer_d(ggthemes, hc_bg, n = 3, centered = TRUE) #original color index: [2, 3, 4]
[1] "#c3d6df" "#ed111a" "#ebebeb"
paletteer_d(ggthemes, hc_bg, n = 4, centered = TRUE, side = "left") #original color index: [1, 2, 3, 4]
[1] "#d5e4eb" "#c3d6df" "#ed111a" "#ebebeb"
paletteer_d(ggthemes, hc_bg, n = 4, centered = TRUE, side = "right") #original color index: [2, 3, 4, 5]
[1] "#c3d6df" "#ed111a" "#ebebeb" "#c9c9c9"
paletteer_d(ggthemes, hc_bg, n = 4, centered = TRUE, side = "middle") #original color index: [1, 2, 4, 5]
[1]  "#d5e4eb" "#c3d6df" "#ebebeb" "#c9c9c9"

Thoughts?

wetlandscapes avatar Aug 15 '19 20:08 wetlandscapes