From 133fee9fce8cab28449aab830b9d15c06328520f Mon Sep 17 00:00:00 2001 From: dicook Date: Thu, 7 Mar 2024 14:17:55 +1100 Subject: [PATCH] palette can now be a vector of colours --- NEWS.md | 1 + R/util.r | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index bba978e4..6c79f173 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ * flea is now standardised measurements, and flea_raw is the original units * TeachingDemos removed as a Suggests, and replaced with aplpack for drawing Chernoff faces * addition of a pre-specified ellipse can be added to the 2D display +* palette can now be a vector of values # tourr 1.1.0 diff --git a/R/util.r b/R/util.r index c2290cd4..dce0ea12 100644 --- a/R/util.r +++ b/R/util.r @@ -122,7 +122,14 @@ areColors <- function(x) { #' @export mapColors <- function(x, palette) { n <- length(unique(x)) - pal <- grDevices::hcl.colors(n, palette=palette) + # Handle manual colour setting + if (length(palette) > 1) { + stopifnot(length(palette) == n) + pal <- palette + } + else { + pal <- grDevices::hcl.colors(n, palette=palette) + } pal[as.numeric(as.factor(x))] }