Skip to content

Feature request: palette registration #396

Closed

Description

@teunbrand

I think it would be great if there was some mechanism in which packages can register a colour palette that then could natively interface with scales/ggplot2. It would save having to write separate scale_colour/fill_*() functions for packages providing the palettes, and save having to write scale_{custom_colour_aesthetic}_{palette_type} for packages that extend layers with custom colour-like aesthetics.

From a palette package POV you might then call

scales::register_palette(name = "foobar", type = "qualitative", fun = my_palette_fun)

This then gets stored in a list from which one could retrieve

scales::pal_registered(type = "qualitative", name = "foobar")

Which then gets used in e.g. ggplot2 scales. A nicety that can be added is to pre-populate these list of registered palettes with R's build-in palettes.

Activity

  1. davidhodge931 commented on Sep 24, 2024

    @davidhodge931

    Awesome work - this will be super useful! I wonder if the set_palette function here could be called register_palette @teunbrand? This might reflect more accurately what it does. I.e. nothing is set for subsequent plots. It's just available to be retrieved. This stuff is subjective, so maybe what you've got is better. I just would expect setting a palette would change the colours by default

  2. teunbrand commented on Sep 25, 2024

    @teunbrand
    CollaboratorAuthor

    Hmm, I like set set_/get_ symmetry, but I suppose it could be set_registered_palette() and get_registered_palette() to make it somewhat less ambiguous.

  3. davidhodge931 commented on Sep 25, 2024

    @davidhodge931

    Hmm, set_registered_palette does look a little long-winded.

    Another idea: set_known_palette and get_known_palette? Think it still could be misinterpreted as setting a default palette for subsequent plots. I suppose people can read the help.

    So think I prefer register_palette for the reason mentioned above. Not sure what to call the get_* one though ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions