Skip to content

Commit

Permalink
palette can now be a vector of colours
Browse files Browse the repository at this point in the history
  • Loading branch information
dicook committed Mar 7, 2024
1 parent e31f32b commit 133fee9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion R/util.r
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
}

Expand Down

0 comments on commit 133fee9

Please sign in to comment.