Skip to content

Use the full range of the palette for binned viridis #4737

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

Merged
merged 3 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions R/scale-viridis.r
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#'
#' @inheritParams scales::viridis_pal
#' @inheritParams scales::gradient_n_pal
#' @param pal_full_range For the binned versions, use the full range of the palette
#' @inheritParams continuous_scale
#' @param ... Other arguments passed on to [discrete_scale()],
#' [continuous_scale()], or [binned_scale] to control name, limits, breaks,
Expand Down Expand Up @@ -123,15 +124,23 @@ scale_fill_viridis_c <- function(..., alpha = 1, begin = 0, end = 1,
scale_colour_viridis_b <- function(..., alpha = 1, begin = 0, end = 1,
direction = 1, option = "D", values = NULL,
space = "Lab", na.value = "grey50",
guide = "coloursteps", aesthetics = "colour") {
binned_scale(
aesthetics,
"viridis_b",
gradient_n_pal(
guide = "coloursteps", aesthetics = "colour", pal_full_range = FALSE) {
if(pal_full_range) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to be an option? Wouldn't you always want to use the full range?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per our discussion in #4372 with @clauswilke @yutannihilation: both ways of doing it could make sense

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please provide an argument as to why the current behaviour would ever be desired?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say that I can. Maybe @clauswilke @yutannihilation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea. I was just saying the current behavior is understandable. I'm not sure what behavior is desirable, sorry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomasp85 should issue a final ruling, but I'm pretty sure the original behaviour was a mistake, and we should just always use the full range. We'll need to flag this as a visual change in the NEWS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree - we should just go with the approach in this PR. The original implementation was an error on my part

pal <- binned_pal(
viridis_pal(alpha, begin, end, direction, option)
)
} else {
pal <- gradient_n_pal(
viridis_pal(alpha, begin, end, direction, option)(6),
values,
space
),
)
}

binned_scale(
aesthetics,
"viridis_b",
pal,
na.value = na.value,
guide = guide,
...
Expand All @@ -143,15 +152,23 @@ scale_colour_viridis_b <- function(..., alpha = 1, begin = 0, end = 1,
scale_fill_viridis_b <- function(..., alpha = 1, begin = 0, end = 1,
direction = 1, option = "D", values = NULL,
space = "Lab", na.value = "grey50",
guide = "coloursteps", aesthetics = "fill") {
binned_scale(
aesthetics,
"viridis_b",
gradient_n_pal(
guide = "coloursteps", aesthetics = "fill", pal_full_range = FALSE) {
if(pal_full_range) {
pal <- binned_pal(
viridis_pal(alpha, begin, end, direction, option)
)
} else {
pal <- gradient_n_pal(
viridis_pal(alpha, begin, end, direction, option)(6),
values,
space
),
)
}

binned_scale(
aesthetics,
"viridis_b",
pal,
na.value = na.value,
guide = guide,
...
Expand Down
8 changes: 6 additions & 2 deletions man/scale_viridis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.