Skip to content

Commit

Permalink
rc 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsumner committed May 5, 2021
1 parent 0131112 commit 56cb4d9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export(bathy_deep_pal)
export(chlPal)
export(chl_pal)
export(col2hex)
export(d_pal)
export(data_pal)
export(icePal)
export(ice_pal)
export(image_pal)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# palr 0.3.0

* New function `d_pal()` and alias `data_pal()` to colour data values (like {colourvalues} but
simpler).

* Removed ftp links thanks to CRAN.

# palr 0.2.0
Expand Down
38 changes: 38 additions & 0 deletions R/data_pal.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#' Colours for data values
#'
#' Scales input data to the palette, so that colour is mapped linearly to the range of values.
#'
#' Default palette 'pal' is the 'viridis' colours of [grDevices::hcl.colors()], and may be literal colour values
#' or a function.
#'
#' [data_pal()] is an alias of [d_pal()].
#'
#' @param x data vector, maybe be numeric or character
#' @param pal palette, may be colours or a function
#'
#' @export
#' @importFrom grDevices hcl.colors
#' @examples
#' plot(1:100, col = d_pal(1:100))
#' plot(1:100, col = d_pal(1:100, chl_pal))
#'
d_pal <- function(x, pal = hcl.colors(84)) {
if (is.function(pal)) {
pal <- pal(84)
}
if (is.character(x)) {
x <- as.integer(factor(x))
}
if (is.factor(x)) {
x <- as.integer(x)
}
x <- x[!is.na(x)]
xx <- (x - min(x)) / diff(range(x))
pal[xx * (length(pal) - 1) + 1]
}

#' @name d_pal
#' @export
data_pal <- function(x, pal = hcl.colors(84)) {
d_pal(x, pal = pal)
}
4 changes: 2 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Removed ftp link for CRAN checks, thank you very much.

## Test environments
* local ubuntu install, R 4.0.4
* local ubuntu install, R 4.0.5
* win-builder (devel)

## R CMD check results
Expand All @@ -17,5 +17,5 @@ The three reverse dependencies pass check with this version.

* quadmesh
* lazyraster
* paleteer
* paletteer

30 changes: 30 additions & 0 deletions man/d_pal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 56cb4d9

Please sign in to comment.