#' Color scale constructor for ust colors
#'
#' @param palette Character name of palette in ust_palettes
#' @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
#'
scale_color_ust <- function(palette = "main", discrete = TRUE, reverse = FALSE, ...) {
if (discrete) {
if (reverse) { pal <- function() { scales::manual_pal(unname(rev(ust_palettes[[palette]]))) }
} else {
pal <- function() { scales::manual_pal(unname(ust_palettes[[palette]])) }
}
ggplot2::discrete_scale("color", paste0("ust_", palette), palette = pal(), ...)
} else {
pal <- ust_pal(palette = palette, reverse = reverse)
ggplot2::scale_color_gradientn(colors = pal(256), ...)
}
}
#' Fill scale constructor for ust colors
#'
#' @param palette Character name of palette in ust_palettes
#' @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
#'
scale_fill_ust <- function(palette = "main", discrete = TRUE, reverse = FALSE, ...) {
if (discrete) {
if (reverse) { pal <- function() { scales::manual_pal(unname(rev(ust_palettes[[palette]]))) }
} else {
pal <- function() { scales::manual_pal(unname(ust_palettes[[palette]])) }
}
ggplot2::discrete_scale("fill", paste0("ust_", palette), palette = pal(), ...)
} else {
pal <- ust_pal(palette = palette, reverse = reverse)
ggplot2::scale_fill_gradientn(colors = pal(256), ...)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.