R/scales.R

Defines functions scale_fill_SLU scale_color_SLU

Documented in scale_color_SLU scale_fill_SLU

#' Color scale constructor for SLU colors
#'
#' @param palette Character name of palette in SLU_palettes
#' @param discrete Boolean indicating whether color aesthetic is discrete or not
#' @param reverse Boolean indicating whether the palette should be reversed
#' @param ... Additional arguments passed to discrete_scale() or
#'            scale_color_gradientn(), used respectively when discrete is TRUE or FALSE
#'
#' @export
scale_color_SLU <- function(palette = "all", discrete = TRUE, reverse = FALSE, ...) {
  pal <- SLU_pal(palette = palette, reverse = reverse)

  if (discrete) {
    ggplot2::discrete_scale("colour", paste0("SLU_", palette), palette = pal, ...)
  } else {
    ggplot2::scale_color_gradientn(colours = pal(256), ...)
  }
}

#' Fill scale constructor for SLU colors
#'
#' @param palette Character name of palette in SLU_palettes
#' @param discrete Boolean indicating whether color aesthetic is discrete or not
#' @param reverse Boolean indicating whether the palette should be reversed
#' @param ... Additional arguments passed to discrete_scale() or
#'            scale_fill_gradientn(), used respectively when discrete is TRUE or FALSE
#'
#' @export
scale_fill_SLU <- function(palette = "all", discrete = TRUE, reverse = FALSE, ...) {
  pal <- SLU_pal(palette = palette, reverse = reverse)

  if (discrete) {
    ggplot2::discrete_scale("fill", paste0("SLU_", palette), palette = pal, ...)
  } else {
    ggplot2::scale_fill_gradientn(colours = pal(256), ...)
  }
}
kagervall/SLUcolors documentation built on Jan. 31, 2024, 11 a.m.