Skip to content

Commit

Permalink
PERF: Let the gradient scales handle missing values
Browse files Browse the repository at this point in the history
Depends on r-lib/scales#371
  • Loading branch information
zeehio committed Nov 6, 2022
1 parent 29524a8 commit 60f6955
Showing 1 changed file with 6 additions and 6 deletions.
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, ...)
}

0 comments on commit 60f6955

Please sign in to comment.