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

Add na.color support to gradient_n_pal, div_gradient_pal, seq_gradient_pal #371

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions R/pal-gradient.r
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
6 changes: 5 additions & 1 deletion man/div_gradient_pal.Rd

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

5 changes: 4 additions & 1 deletion man/gradient_n_pal.Rd

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

10 changes: 9 additions & 1 deletion man/seq_gradient_pal.Rd

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