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

PERF: Let the gradient scales handle missing values #5034

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
12 changes: 6 additions & 6 deletions R/scale-gradient.r
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@
#'
scale_colour_gradient <- function(..., low = "#132B43", high = "#56B1F7", space = "Lab",
na.value = "grey50", guide = "colourbar", aesthetics = "colour") {
continuous_scale(aesthetics, "gradient", seq_gradient_pal(low, high, space),
continuous_scale(aesthetics, "gradient", seq_gradient_pal(low, high, space, na.color = na.value),
na.value = na.value, guide = guide, ...)
}

#' @rdname scale_gradient
#' @export
scale_fill_gradient <- function(..., low = "#132B43", high = "#56B1F7", space = "Lab",
na.value = "grey50", guide = "colourbar", aesthetics = "fill") {
continuous_scale(aesthetics, "gradient", seq_gradient_pal(low, high, space),
continuous_scale(aesthetics, "gradient", seq_gradient_pal(low, high, space, na.color = na.value),
na.value = na.value, guide = guide, ...)
}

Expand All @@ -96,7 +96,7 @@ scale_colour_gradient2 <- function(..., low = muted("red"), mid = "white", high
midpoint = 0, space = "Lab", na.value = "grey50", guide = "colourbar",
aesthetics = "colour") {
continuous_scale(aesthetics, "gradient2",
div_gradient_pal(low, mid, high, space), na.value = na.value, guide = guide, ...,
div_gradient_pal(low, mid, high, space, na.color = na.value), na.value = na.value, guide = guide, ...,
rescaler = mid_rescaler(mid = midpoint))
}

Expand All @@ -106,7 +106,7 @@ scale_fill_gradient2 <- function(..., low = muted("red"), mid = "white", high =
midpoint = 0, space = "Lab", na.value = "grey50", guide = "colourbar",
aesthetics = "fill") {
continuous_scale(aesthetics, "gradient2",
div_gradient_pal(low, mid, high, space), na.value = na.value, guide = guide, ...,
div_gradient_pal(low, mid, high, space, na.color = na.value), na.value = na.value, guide = guide, ...,
rescaler = mid_rescaler(mid = midpoint))
}

Expand All @@ -125,7 +125,7 @@ scale_colour_gradientn <- function(..., colours, values = NULL, space = "Lab", n
colours <- if (missing(colours)) colors else colours

continuous_scale(aesthetics, "gradientn",
gradient_n_pal(colours, values, space), na.value = na.value, guide = guide, ...)
gradient_n_pal(colours, values, space, na.color = na.value), na.value = na.value, guide = guide, ...)
}
#' @rdname scale_gradient
#' @export
Expand All @@ -134,5 +134,5 @@ scale_fill_gradientn <- function(..., colours, values = NULL, space = "Lab", na.
colours <- if (missing(colours)) colors else colours

continuous_scale(aesthetics, "gradientn",
gradient_n_pal(colours, values, space), na.value = na.value, guide = guide, ...)
gradient_n_pal(colours, values, space, na.color = na.value), na.value = na.value, guide = guide, ...)
}