Add a fallback palette based on Viridis

This commit is contained in:
gnoblet 2023-02-19 17:49:00 -05:00
parent 133a4b29b0
commit a8ff478e21

19
R/pal_fallback.R Normal file
View file

@ -0,0 +1,19 @@
pal_fallback <- function(reverse = FALSE,
color_ramp_palette = FALSE,
discrete = FALSE,
n = 5,
...){
pal <- if(discrete) { viridisLite::viridis(n) } else {viridisLite::magma(n)}
if (reverse) pal <- rev(pal)
if (color_ramp_palette) {
rlang::check_installed("grDevices", reason = "Package \"grDevices\" needed for `pal_fallback()` with 'color_ramp_palette' set to `TRUE` to work. Please install it.")
pal <- grDevices::colorRampPalette(pal, ...)
}
return(pal)
}