Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Add built-in support for viridis color scales #2178
Conversation
karawoo
requested a review
from hadley
Jun 22, 2017
| @@ -0,0 +1,68 @@ | ||
| +#' Viridis colour scales from viridisLite | ||
| +#' | ||
| +#' @description |
| +#' The `viridis` scales provide color maps that are perceptually uniform in both | ||
| +#' color and black-and-white. They are also designed to be perceived by viewers | ||
| +#' with common forms of color blindness. See also | ||
| +#' \url{https://bids.github.io/colormap/}. |
| +#' @export | ||
| +scale_colour_viridis_discrete <- function(..., alpha = 1, begin = 0, end = 1, | ||
| + direction = 1, option = "D") { | ||
| + discrete_scale("colour", "viridis_discrete", |
hadley
Jun 22, 2017
Owner
Can you please use tidyverse style here: http://style.tidyverse.org/syntax.html#long-lines
| +#' @inheritParams viridisLite::viridis | ||
| +#' @export | ||
| +#' @rdname scale_viridis | ||
| +viridis_pal <- function(alpha = 1, begin = 0, end = 1, direction = 1, option= "D") { |
hadley
Jun 22, 2017
Owner
Yes, this should probably go into scales. You'll need to do a PR to scales, including a bump to the version number. Then in this PR, you'll need to adjust the version of scales required in the description, and add Remotes: hadley/scales.
|
I need to add some examples to the documentation here. Should I test these scales as well? |
|
Added a couple tests, one of which very awkwardly (!) checks that scales named |
| + | ||
| +df <- data.frame(x = 1, y = 1, z = "a") | ||
| + | ||
| +test_that("Viridis color scale gets used", { |
| + geom_point() | ||
| + p2 <- p1 + scale_colour_viridis_d() | ||
| + | ||
| + expect_false(layer_data(p1)$colour == layer_data(p2)$colour) |
| +#' # The above are equivalent to | ||
| +#' v + scale_fill_gradient() | ||
| +#' v + scale_fill_viridis_c() | ||
| +scale_colour_continuous <- function(..., |
hadley
Jul 3, 2017
Owner
I now think it's probably better form to use the second argument to getOption(), rather than setting on load.
| + gradient_n_pal( | ||
| + viridis_pal(alpha, begin, end, direction, option)(6), | ||
| + values, | ||
| + space), |
| @@ -1,5 +1,7 @@ | ||
| # ggplot2 2.2.1.9000 | ||
| +* Add built-in support for `viridis` and related color maps (@karawoo). |
This was referenced Jul 5, 2017
karawoo
added some commits
Jun 21, 2017
karawoo
merged commit 77fc5c7
into
tidyverse:master
Jul 13, 2017
karawoo
added a commit
to karawoo/ggplot2
that referenced
this pull request
Jul 14, 2017
|
|
karawoo + karawoo |
0a57d75
|
karawoo commentedJun 22, 2017
Related to 1526. This is a first stab at adding built-in support for
viridiscolor scales using theviridisLitepackage. The function names are kind of long and awkward right now, but I'm not sure what better names would be. Also, should theviridis_palfunction go as a PR to scales instead of ggplot2?