commit 53ec0626fea9a977460cc332ba88d1df56a11679
parent 4a64535d7641b8076c37dcba7a4e34160d6f1b7e
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date: Wed, 8 Sep 2021 06:53:17 -0400
Function to create palette functions
Diffstat:
1 file changed, 30 insertions(+), 0 deletions(-)
diff --git a/seq_dissim_palette.R b/seq_dissim_palette.R
@@ -0,0 +1,30 @@
+
+#' Sequential dissimilarity palette
+#'
+#' Returns a palette function that, given a number `n` will return a sequence of
+#' decreasingly dissimilar colors. If `n` is greater than the number of colors
+#' specified, it falls back to a color ramp (in the same order used for the
+#' sequence of dissimilar colors). If you definitely want a color ramp it's best
+#' to call that directly.
+#'
+#' @param cols A list of color names
+#' @param cvd A color vision deficiency
+#'
+#' @return A palette function
+#' @export
+#'
+#' @examples
+#' seq_dissim_palette(c('orangered2', 'dodgerblue4', 'black', 'white'))(3)
+#'
+#' seq_dissim_palette(c('orangered2', 'dodgerblue4', 'black', 'white'))(6)
+seq_dissim_palette <- function(cols, cvd = 'deuteranomaly') {
+ dissim_mat <- cvd_dissimilarity(cols, cvd)
+ color_sequence <- seq_dissim_colors(dissim_mat)
+
+ function(n) {
+ if (n <= length(cols))
+ cols[color_sequence[seq(n)]]
+ else
+ grDevices::colorRampPalette(cols[color_sequence], space = 'Lab')(n)
+ }
+}