Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to create a new color palette #152

Open
JosiahParry opened this issue Apr 18, 2024 · 7 comments
Open

Ability to create a new color palette #152

JosiahParry opened this issue Apr 18, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@JosiahParry
Copy link

I'd like to be able to provide say 5 colors as hex codes as a new palette. Then I'd be able to use that new hypothetical palette with palette_dynamic() to get the color interpolation. E.g

my_pal <- palette_new(c("red", "white", "blue"))

palette_dynamic(my_pal, n = 5)
@EmilHvitfeldt EmilHvitfeldt added the enhancement New feature or request label Apr 19, 2024
@EmilHvitfeldt
Copy link
Owner

This is not a bad idea so I'm going to entertain it. However it might be a challenge as the package right now, relies on a lot of precomputed objects such as paletteer::palettes_d

@mschilli87
Copy link

mschilli87 commented May 21, 2024

If anyone is going to tackle this, I'd love the solution to work based on a single color as well. Often I find myself having fixed colors for specific categories and needing to distinguish several sub-classes within those. So if I could generate let's say two palettes with three colors each, one with three different reds based on my red of reference and the other one with three different blues, based on my blue of reference, by slightly varying the based colors in HCL space, that would be extremely useful for me.

@JosiahParry
Copy link
Author

@mschilli87 have you seen https://uicolors.app/create it could be helpful! I use it with tailwind css for palette generation i can imagine you can explore this in R

@mschilli87
Copy link

@JosiahParry: Thx. I'll have a look. I also found https://mdigi.tools/color-shades which basically does what I want. But I'd like to have a way to get those in R directly because at the number of colors I need depends on the input data, so I'm kinda looking for

base_color <- "#aa55ff"

# ...lot's of code...

n_categories <- # ...some code determining the required number of colors

# ...more code...

colors <- magic_funtion(base_color, n_categories)

resulting in colors being c("#d4aaff", "#7f00ff", "#2a0055") if n_categories equals 3 and c("#e5ccff", "#b266ff", "#7f00ff", "#4c0099", "#190033") if n_categories equals 5, respectively.

@xx02al
Copy link

xx02al commented Nov 1, 2024

@mschilli87 if I don't get you wrong you're looking for something like this

paletteer_monochrome_bw <- function(colour, n_colours) {

  # input checks removed for demo

  temp_n <- floor(n_colours / 2) + 1
  blk <- prismatic::clr_mix(
    rep("black", temp_n), colour, seq(0.2, 1, length.out = temp_n)
    )
  wht <- prismatic::clr_mix(
    rep("white", temp_n), colour, seq(0.2, 1, length.out = temp_n)
    )
  pre_res <- unclass(union(blk, rev(wht)))
  # dirty removal of alpha channel, which is set to FF by `clr_mix()`
  gsub("(#[[:alnum:]]{6})FF$", "\\1", pre_res)

}

however, I am not sure, if {paletteer} is the right place for implementation. the monochromeR package aimed at something similar, but is currently in need of revision (I suggested options to do so and @cararthompson is currently thinking about it). what do you think about this @EmilHvitfeldt, @mschilli87, @cararthompson?

@cararthompson
Copy link

Thanks for the mention @xx02al !

Just to clarify, {monochromeR} does currently work, and is available on CRAN - the improvements are to do with streamlining the code and function philosophies. You can read my write-up with a demo here. I've also turned it into a shiny app which has a few extra functionalities.

https://www.cararthompson.com/shinyapps/2022-01-11-monochromer/monochromer

Hope this helps!

@mschilli87
Copy link

@xx02al: This is exactly the kind of function I was looking for. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants