From 8404c2218ab118de497f4e92091cb07499020553 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 6 Nov 2022 12:43:09 +0100 Subject: [PATCH 1/2] gradient_n_pal, div_gradient_pal, seq_gradient_pal accept na.color --- R/pal-gradient.r | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/R/pal-gradient.r b/R/pal-gradient.r index aff3ce1a..29485d10 100644 --- a/R/pal-gradient.r +++ b/R/pal-gradient.r @@ -7,13 +7,15 @@ #' to map an arbitrary range to between 0 and 1. #' @param space colour space in which to calculate gradient. Must be "Lab" - #' other values are deprecated. +#' @param na.color The color to use for missing values. By default missing +#' values are left missing. #' @export -gradient_n_pal <- function(colours, values = NULL, space = "Lab") { +gradient_n_pal <- function(colours, values = NULL, space = "Lab", na.color = NA) { if (!identical(space, "Lab")) { lifecycle::deprecate_warn("0.3.0", "gradient_n_pal(space = 'only supports be \"Lab\"')") } - ramp <- colour_ramp(colours) + ramp <- colour_ramp(colours, na.color = na.color) force(values) function(x) { @@ -49,8 +51,8 @@ gradient_n_pal <- function(colours, values = NULL, space = "Lab") { #' pal <- div_gradient_pal(low = mnsl(complement("10R 4/6"), fix = TRUE)) #' image(r, col = pal(seq(0, 1, length.out = 100))) #' @importFrom munsell mnsl -div_gradient_pal <- function(low = mnsl("10B 4/6"), mid = mnsl("N 8/0"), high = mnsl("10R 4/6"), space = "Lab") { - gradient_n_pal(c(low, mid, high), space = space) +div_gradient_pal <- function(low = mnsl("10B 4/6"), mid = mnsl("N 8/0"), high = mnsl("10R 4/6"), space = "Lab", na.color = NA) { + gradient_n_pal(c(low, mid, high), space = space, na.color = na.color) } #' Sequential colour gradient palette (continuous) @@ -66,6 +68,6 @@ div_gradient_pal <- function(low = mnsl("10B 4/6"), mid = mnsl("N 8/0"), high = #' #' library(munsell) #' show_col(seq_gradient_pal("white", mnsl("10R 4/6"))(x)) -seq_gradient_pal <- function(low = mnsl("10B 4/6"), high = mnsl("10R 4/6"), space = "Lab") { - gradient_n_pal(c(low, high), space = space) +seq_gradient_pal <- function(low = mnsl("10B 4/6"), high = mnsl("10R 4/6"), space = "Lab", na.color = NA) { + gradient_n_pal(c(low, high), space = space, na.color = na.color) } From 8bc09df17bf5d88a7866eea68b0714e50f89d1c9 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 6 Nov 2022 12:46:35 +0100 Subject: [PATCH 2/2] devtools::document() --- man/div_gradient_pal.Rd | 6 +++++- man/gradient_n_pal.Rd | 5 ++++- man/seq_gradient_pal.Rd | 10 +++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/man/div_gradient_pal.Rd b/man/div_gradient_pal.Rd index da3910c1..a7da4bed 100644 --- a/man/div_gradient_pal.Rd +++ b/man/div_gradient_pal.Rd @@ -8,7 +8,8 @@ div_gradient_pal( low = mnsl("10B 4/6"), mid = mnsl("N 8/0"), high = mnsl("10R 4/6"), - space = "Lab" + space = "Lab", + na.color = NA ) } \arguments{ @@ -20,6 +21,9 @@ div_gradient_pal( \item{space}{colour space in which to calculate gradient. Must be "Lab" - other values are deprecated.} + +\item{na.color}{The color to use for missing values. By default missing +values are left missing.} } \description{ Diverging colour gradient (continuous). diff --git a/man/gradient_n_pal.Rd b/man/gradient_n_pal.Rd index b560dd3e..1ebdfba4 100644 --- a/man/gradient_n_pal.Rd +++ b/man/gradient_n_pal.Rd @@ -4,7 +4,7 @@ \alias{gradient_n_pal} \title{Arbitrary colour gradient palette (continuous)} \usage{ -gradient_n_pal(colours, values = NULL, space = "Lab") +gradient_n_pal(colours, values = NULL, space = "Lab", na.color = NA) } \arguments{ \item{colours}{vector of colours} @@ -16,6 +16,9 @@ to map an arbitrary range to between 0 and 1.} \item{space}{colour space in which to calculate gradient. Must be "Lab" - other values are deprecated.} + +\item{na.color}{The color to use for missing values. By default missing +values are left missing.} } \description{ Arbitrary colour gradient palette (continuous) diff --git a/man/seq_gradient_pal.Rd b/man/seq_gradient_pal.Rd index 15976d74..6d499b09 100644 --- a/man/seq_gradient_pal.Rd +++ b/man/seq_gradient_pal.Rd @@ -4,7 +4,12 @@ \alias{seq_gradient_pal} \title{Sequential colour gradient palette (continuous)} \usage{ -seq_gradient_pal(low = mnsl("10B 4/6"), high = mnsl("10R 4/6"), space = "Lab") +seq_gradient_pal( + low = mnsl("10B 4/6"), + high = mnsl("10R 4/6"), + space = "Lab", + na.color = NA +) } \arguments{ \item{low}{colour for low end of gradient.} @@ -13,6 +18,9 @@ seq_gradient_pal(low = mnsl("10B 4/6"), high = mnsl("10R 4/6"), space = "Lab") \item{space}{colour space in which to calculate gradient. Must be "Lab" - other values are deprecated.} + +\item{na.color}{The color to use for missing values. By default missing +values are left missing.} } \description{ Sequential colour gradient palette (continuous)