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

Provide hooks for ggplot2 gradient and discrete scales #3

Open
coatless opened this issue Aug 1, 2017 · 4 comments
Open

Provide hooks for ggplot2 gradient and discrete scales #3

coatless opened this issue Aug 1, 2017 · 4 comments

Comments

@coatless
Copy link
Collaborator

coatless commented Aug 1, 2017

Think about adding some hooks for ggplot2... (Package will have more dependencies though... )

@brianwdavis
Copy link

I'm writing a package that implements a particular discrete mapping of continuous color maps. In order to provide support for cetcolor I wrote a thin wrapper:

cet_discrete_pal <- function(...) {
  function(n) {
    cet_pal(n, ...)
  }
}

This returns a function that only takes argument n and returns a vector of colors. That way cet_discrete_pal behaves just like hue_pal, brewer_pal, and viridis_pal.

You can use it like so:

scale_color_cet <- function(guide = "legend", ...) {
  discrete_scale("colour", "cet", guide = guide, palette = cet_discrete_pal(...))
}

And then in use:

ggplot(diamonds, aes(clarity, price, color = clarity)) + 
  geom_boxplot() +
  scale_color_cet(name = "bgy")

image

Feel free to run with it, but it would be nice if cet_discrete_pal (or similarly named) would be in a future release, so it could be called in the same way using the discrete_scale API.

@coatless
Copy link
Collaborator Author

@brianwdavis thanks. To keep dependencies low, I may write a second package that hooks into cetcolor with the aforementioned ggplot2 support.

@coatless
Copy link
Collaborator Author

@brianwdavis, I forgot to ask, when do you need this by?

@brianwdavis
Copy link

I've not really got any timeframe. I will probably just include the cet_discrete_pal() and deprecate it later if you implement something similar.

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

No branches or pull requests

2 participants