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

Port improvements to color mapping functions from leaflet #191

Merged
merged 5 commits into from
Nov 20, 2018

Conversation

jcheng5
Copy link
Member

@jcheng5 jcheng5 commented Nov 14, 2018

  • col_numeric(), col_bin(), col_quantile(), and col_factor() now support
    viridis colors. Just pass a palette name ("magma", "inferno", "plasma",
    or "viridis") as the palette argument.

  • col_numeric(), col_bin(), col_quantile(), and col_factor() now have a
    reverse parameter, to apply color palettes in the opposite of their usual
    order (i.e. high-to-low instead of low-to-high).

  • col_bin() and col_quantile() now take a right argument, which is passed
    to base::cut(); it indicates whether the bin/quantile intervals should be
    closed on the right (and open on the left), or vice versa.

  • col_factor() now tries to avoid interpolating qualitative RColorBrewer
    palettes. Instead, it attempts to assign a palette color to each factor level.
    Interpolation will still be used if there are more factor levels than
    available colors, and a warning will be emitted in that case.

@jcheng5 jcheng5 force-pushed the joe/feature/col-mapping-improvement branch from 3368bf2 to ae0e520 Compare November 14, 2018 00:43
R/colour-mapping.r Outdated Show resolved Hide resolved
R/colour-mapping.r Outdated Show resolved Hide resolved
R/colour-mapping.r Outdated Show resolved Hide resolved
tests/testthat/test-colors-advanced.r Outdated Show resolved Hide resolved
tests/testthat/test-colors-advanced.r Outdated Show resolved Hide resolved
tests/testthat/test-colors-advanced.r Outdated Show resolved Hide resolved
Note the long comment on test-colors-advanced.r:118;
this represents differing behavior from the original
versions of these functions in leaflet.
@jcheng5
Copy link
Member Author

jcheng5 commented Nov 14, 2018

@hadley I've implemented your suggestions. There's one significant difference in behavior between my brewer_pal_colors and brewer_pal, that occurs when you request 2 colors from an RColorBrewer palette (such as when coloring a factor with only 2 levels). The RColorBrewer::brewer.pal call will return three colors; brewer_pal_colors will use the first and third, while brewer_pal will use the first and second.

Here's a demonstration of the differences:
http://rpubs.com/jcheng/small-palettes

I thought I'd feel more strongly about the leaflet version being superior, but now looking at that link, I'm not sure it's that big of a deal either way. I do think that for Sequential/Blues the leaflet version looks better, and for Qualitative/Accent the scales version looks better.

@hadley
Copy link
Member

hadley commented Nov 15, 2018

I don't feel particularly strongly, but I do think return the first two colours is more consistent that returning the first and the third.

@jcheng5
Copy link
Member Author

jcheng5 commented Nov 16, 2018

@hadley I'm fine with that. Let me know if you see anything else I need to change--otherwise I think it's done.

R/colour-mapping.r Outdated Show resolved Hide resolved
@hadley hadley merged commit 7cd8121 into master Nov 20, 2018
@jcheng5 jcheng5 deleted the joe/feature/col-mapping-improvement branch November 21, 2018 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants