diff --git a/DESCRIPTION b/DESCRIPTION index 1db60ad6..3e37259d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: scales -Version: 0.4.1.9000 +Version: 0.4.1.9001 Authors@R: c( person("Hadley", "Wickham", , "hadley@rstudio.com", c("aut", "cre")), person("RStudio", role = "cph") @@ -19,7 +19,8 @@ Imports: munsell (>= 0.2), labeling, methods, - Rcpp + Rcpp, + viridisLite LinkingTo: Rcpp Suggests: testthat (>= 0.8), diff --git a/NAMESPACE b/NAMESPACE index 9dafe0e0..88bc51ab 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -87,6 +87,7 @@ export(trans_format) export(trans_new) export(trans_range) export(unit_format) +export(viridis_pal) export(wrap_format) export(zero_range) importFrom(Rcpp,evalCpp) diff --git a/NEWS.md b/NEWS.md index cbff0520..4d203a5f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,7 @@ -# scales 0.4.1.9000 +# scales 0.4.1.9001 + +* Adds `viridis_pal()` for creating palettes with color maps from the + viridisLite package (@karawoo). # scales 0.4.1 diff --git a/R/pal-viridis.r b/R/pal-viridis.r new file mode 100644 index 00000000..85dafd37 --- /dev/null +++ b/R/pal-viridis.r @@ -0,0 +1,15 @@ +#' Viridis palette +#' +#' @inheritParams viridisLite::viridis +#' @references \url{https://bids.github.io/colormap/} +#' @export +#' @examples +#' show_col(viridis_pal()(10)) +#' show_col(viridis_pal(direction = -1)(6)) +#' show_col(viridis_pal(begin = 0.2, end = 0.8)(4)) +#' show_col(viridis_pal(option = "plasma")(6)) +viridis_pal <- function(alpha = 1, begin = 0, end = 1, direction = 1, option= "D") { + function(n) { + viridisLite::viridis(n, alpha, begin, end, direction, option) + } +} diff --git a/man/viridis_pal.Rd b/man/viridis_pal.Rd new file mode 100644 index 00000000..391883bc --- /dev/null +++ b/man/viridis_pal.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pal-viridis.r +\name{viridis_pal} +\alias{viridis_pal} +\title{Viridis palette} +\usage{ +viridis_pal(alpha = 1, begin = 0, end = 1, direction = 1, + option = "D") +} +\arguments{ +\item{alpha}{The alpha transparency, a number in [0,1], see argument alpha in +\code{\link[grDevices]{hsv}}.} + +\item{begin}{The (corrected) hue in [0,1] at which the viridis colormap begins.} + +\item{end}{The (corrected) hue in [0,1] at which the viridis colormap ends.} + +\item{direction}{Sets the order of colors in the scale. If 1, the default, colors +are ordered from darkest to lightest. If -1, the order of colors is reversed.} + +\item{option}{A character string indicating the colormap option to use. Four +options are available: "magma" (or "A"), "inferno" (or "B"), "plasma" (or "C"), +and "viridis" (or "D", the default option).} +} +\description{ +Viridis palette +} +\examples{ +show_col(viridis_pal()(10)) +show_col(viridis_pal(direction = -1)(6)) +show_col(viridis_pal(begin = 0.2, end = 0.8)(4)) +show_col(viridis_pal(option = "plasma")(6)) +} +\references{ +\url{https://bids.github.io/colormap/} +}