Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
^.*\.Rproj$
^\.Rproj\.user$
.DS_Store
data-raw
scratch
man-roxygen
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.Rproj.user
.Rhistory
.RData
*.DS_Store*
# ignore HTML file produced by knitr for the README
README.html
# ignore scratch files
Expand Down
27 changes: 17 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
Package: chroma
Type: Package
Title: Parse and Manipulate Colors, Create Perceptually Correct Color Palettes
Version: 0.2
Date: 2016-02-19
Authors@R: c(person("Jean-Olivier", "Irisson", email="irisson@normalesup.org", role=c("aut", "cre")), person("Gregor", "Aisch", role="aut"))
Description: This package is mostly an R wrapper for the excellent chroma.js library by Gregor Aisch. It allows to parse colors specified in many forms (RGB, HSL, HSV, HCL, etc.), manipulate those colors (saturate, darken, etc.), and create color palettes adequate for human perception (i.e. in the HCL color model). In addition it provides access to a few pre-built color palettes that have been tested perceptually (cubehelix, ColorBrewer, viridis, etc.) and/or are useful (ETOPO1 maps, Wikipedia topographic maps, light wavelentgh, etc.).
Version: 0.2.0.900
Authors@R: c(
person("Jean-Olivier", "Irisson", email="irisson@normalesup.org", role=c("aut", "cre")),
person("Gregor", "Aisch", role="aut"))
Description: Parse colors specified in many forms (RGB, HSL, HSV, HCL, etc.), manipulate those
colors (saturate, darken, etc.), and create color palettes adequate for human perception (i.e. in
the HCL color model). In addition, it provides access to a few pre-built color palettes that
have been tested perceptually (cubehelix, ColorBrewer, viridis, etc.) and/or are useful
(ETOPO1 maps, Wikipedia topographic maps, light wavelentgh, etc.). This package is an R
wrapper for the 'chroma.js' library by Gregor Aisch.
License: GPL-3
LazyData: TRUE
Encoding: UTF-8
Depends: R (>= 2.10)
Depends: R (>= 3.6.0)
Imports:
V8,
grid,
grDevices,
scales,
stringr,
stats
RoxygenNote: 7.2.1
stats,
ggplot2
Suggests:
testthat,
ggplot2,
knitr,
rmarkdown,
colorspace
VignetteBuilder: knitr
RoxygenNote: 7.3.3
URL: https://github.com/jiho/chroma
BugReports: https://github.com/jiho/chroma/issues
Encoding: UTF-8
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ export(viridis_colors)
export(viridis_map)
export(viridis_palette)
export(viridis_scale)
export(vsup_colors)
export(vsup_map)
export(vsup_palette)
export(vsup_scale)
export(wavelength)
export(wikitopo_colors)
export(wikitopo_map)
Expand Down
6 changes: 3 additions & 3 deletions R/compute_deltaE.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' @return A number quantifying the difference between x and y (or a vector thereof). A difference < 1 is imperceptible to the human eye.
#'
#' @references Sharma, Gaurav; Wu, Wencheng; Dalal, Edul N. (2005). "The CIEDE2000 color-difference formula: Implementation notes, supplementary test data, and mathematical observations" (PDF). Color Research & Applications (Wiley Interscience) 30 (1): 21–30. doi:10.1002/col.20070
#' @references Sharma, Gaurav; Wu, Wencheng; Dalal, Edul N. (2005). "The CIEDE2000 color-difference formula: Implementation notes, supplementary test data, and mathematical observations" (PDF). Color Research & Applications (Wiley Interscience) 30 (1): 21–30. \doi{doi:10.1002/col.20070}
#'
#' @export
#' @importFrom stats na.omit
Expand Down Expand Up @@ -103,9 +103,9 @@ deltaE_lab <- function(x1, x2) {
} else {
if (abs(diffhprime) <= 180) {
hbarprime <- sumhprime / 2
} else if (abs(diffhprime) > 180 & sumhprime < 360) {
} else if (abs(diffhprime) > 180 && sumhprime < 360) {
hbarprime <- (sumhprime + 360) / 2
} else if (abs(diffhprime) > 180 & sumhprime >= 360) {
} else if (abs(diffhprime) > 180 && sumhprime >= 360) {
hbarprime <- (sumhprime - 360) / 2
} else {
stop("Should not be possible")
Expand Down
11 changes: 10 additions & 1 deletion R/data_objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@
#' \item{x,y}{x and y coordinates, in degrees.}
#' \item{z}{altitudes, in m.}
#' }
#' @source Extracted from NOAA's NGDC database (\url{https://maps.ngdc.noaa.gov/viewers/wcs-client/}) and regridded.
#' @source Extracted from NOAA's NGDC database (\code{https://maps.ngdc.noaa.gov/viewers/wcs-client/}) and regridded.
"thai"

#' @rdname thai
"thaixyz"


#' Scientific Colour Maps
#' @source https://www.fabiocrameri.ch/colourmaps/
"scicol"

#' Scientific Colour Maps Info
#' @source https://www.fabiocrameri.ch/colourmaps/
"scicol_info"
2 changes: 1 addition & 1 deletion R/hue.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#' # = works, but is a bit less predictable with hcl().
hue <- function(x, model="hsv", modulo=TRUE) {
# deal with the special case of all numeric/empty vectors first, for performance purposes
if (is.numeric(x) | all(is.na(x))) {
if (is.numeric(x) || all(is.na(x))) {
out <- x
} else {
# check inputs
Expand Down
9 changes: 6 additions & 3 deletions R/manip_alpha.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
#' alpha(c("red", "green", "blue"), 0.5)
#' alpha("red", c(0.2, 0.5, 0.7))
#' alpha(c("red", "green", "blue"), c(0.2, 0.5, 0.7))
#' alpha(c("red", "green", "blue", "purple"), c(0.2, 0.5))
#' \dontrun{alpha(c("red", "green", "blue", "purple"), c(0.2, 0.5, 0.7))
#' # = fails because arguments have incompatible lengths (x = 4, alpha = 3)}
#'
#' \dontrun{
#' alpha(c("red", "green", "blue", "purple"), c(0.2, 0.5))
#' alpha(c("red", "green", "blue", "purple"), c(0.2, 0.5, 0.7))
#' # = fail because arguments have incompatible lengths
#' }
#' # Beware, other functions do not support alpha channels
#' mix(alpha("red"), alpha("blue"))
#' mix("red", "blue")
Expand Down
2 changes: 1 addition & 1 deletion R/manip_luminance.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Get or set the relative brightness of colors
#'
#' @details
#' \code{luminance} gets the relative brightness of colors, normalised to 0 for darkest black and 1 for lightest white according to the WCAG definition \url{http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef}.
#' \code{luminance} gets the relative brightness of colors, normalised to 0 for darkest black and 1 for lightest white according to the WCAG definition \url{https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef}.
#'
#' \code{luminance<-} sets the relative brightness by interpolating with black or white until the appropriate relative luminance is found. The changes in luminance are not reversible because the interpolation to black or white changes various aspects of the color simultaneously: its lightness of course but also its intensity and even possibly its hue (at the extreme, black or white have no well-defined hue).
#'
Expand Down
2 changes: 1 addition & 1 deletion R/parse_cmyk.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ cmyk <- function(c=0, m=0.6, y=0.6, k=0.4) {
colors <- parse_color(x, "cmyk")

return(colors)
}
}
4 changes: 2 additions & 2 deletions R/parse_color.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ parse_color <- function(x, model) {

} else {

if (!(is.matrix(x) | is.data.frame(x))) {
if (!(is.matrix(x) || is.data.frame(x))) {
stop("x should be a matrix or data.frame")
}

Expand All @@ -47,7 +47,7 @@ parse_color <- function(x, model) {
}
if (ncol(x) > required_columns) {
warning("only the first ", required_columns, " columns of x will be used")
x <- x[,1:required_columns,drop=F]
x <- x[,1:required_columns,drop=FALSE]
}

}
Expand Down
2 changes: 1 addition & 1 deletion R/parse_css.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' CSS color specification
#'
#' Converts colors specified as CSS strings into R colors. This includes all colors in the X11 specification of the W3C \url{http://www.w3.org/TR/css3-color/#svg-color} as well as \code{rgb()} and \code{hsl()} constructs (but, in this case, it is probably easier to use the functions \code{\link{rgb}}) and \code{\link{hsl}} directly).
#' Converts colors specified as CSS strings into R colors. This includes all colors in the X11 specification of the W3C \url{https://www.w3.org/TR/css-color-3/#svg-color} as well as \code{rgb()} and \code{hsl()} constructs (but, in this case, it is probably easier to use the functions \code{\link{rgb}}) and \code{\link{hsl}} directly).
#'
#' @param x string representing a color in CSS.
#'
Expand Down
6 changes: 4 additions & 2 deletions R/parse_hex.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
#' x <- c("#ff3399", # hex specification valid in R
#' "F39", # hex specification not valid in R
#' "whitesmoke", # named color valid in R and CSS
#' "darkorchid2", # named R color (not existing in CSS)
#' "rebeccapurple" # named CSS color (not existing in R)
#' "darkorchid2" # named R color (not existing in CSS)
#' )
#' hex(x)
#'
Expand All @@ -38,3 +37,6 @@ hex <- function(x) {
# parse the rest
parse_color(x, "hex")
}
# TODO handle named CSS color (not existing in R)
# hex("rebeccapurple") throws error with "chroma.hex('rebeccapurple').hex()" in parse_color
# should be called with parse_color(x, "css")
2 changes: 1 addition & 1 deletion R/parse_wavelength.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' \item{wl}{the wavelength, in nm.}
#' \item{color}{the hex code of the corresponding color.}
#' }
#' @details As explained by the author, David Eccles: "Colour ranges were taken from 'CRC Handbook of Fundamental Spectroscopic Correlation Charts' (see \url{https://en.wikipedia.org/wiki/Visible_spectrum}). Spectral XYZ locus coordinates were found at \url{http://www.cie.co.at/main/freepubs.html}. Every 10nm, the spectral locus point was used as the initial point in a search for a matching sRGB colour (assuming "Dim" viewing condition). The search was carried out by a binary search along a line in JCh space between the spectral point, and a point with 0.3 * brightness (J), 0 chroma (C), and the same hue (h) as the spectral point. The search finished when a point was found that was in sRGB space. The CAT02 matrix was modified as suggested in Brill(2008) \url{https://doi.org/10.1002/col.20432} to reduce yellow-blue problems by replacing the bottom row (0.0030, 0.0136, 0.9834) with (0,0,1). An iterative smoothing was carried out to eliminate the largest jumps in chroma (greater than 5\% change). Code used to generate the colour gradient can be found at \url{http://www.gringene.org/code/spectrum.r}."
#' @details As explained by the author, David Eccles: "Colour ranges were taken from 'CRC Handbook of Fundamental Spectroscopic Correlation Charts' (see \url{https://en.wikipedia.org/wiki/Visible_spectrum}). Spectral XYZ locus coordinates were found at \code{https://www.cie.co.at/main/freepubs.html}. Every 10nm, the spectral locus point was used as the initial point in a search for a matching sRGB colour (assuming "Dim" viewing condition). The search was carried out by a binary search along a line in JCh space between the spectral point, and a point with 0.3 * brightness (J), 0 chroma (C), and the same hue (h) as the spectral point. The search finished when a point was found that was in sRGB space. The CAT02 matrix was modified as suggested in Brill(2008) \doi{doi:10.1002/col.20432} to reduce yellow-blue problems by replacing the bottom row (0.0030, 0.0136, 0.9834) with (0,0,1). An iterative smoothing was carried out to eliminate the largest jumps in chroma (greater than 5\% change). Code used to generate the colour gradient can be found at \code{https://www.gringene.org/code/spectrum.r}."
#' @source \url{https://en.wikipedia.org/wiki/Visible_spectrum#/media/File:Linear_visible_spectrum.svg}
#' @seealso \code{\link{wavelength}} which uses the table to convert any wavelength value to an R color.
"visible"
Expand Down
2 changes: 1 addition & 1 deletion R/persp_facets.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#'
#' @export
persp_facets <- function(z) {
if (!is.matrix(z) | !is.numeric(z)) {
if (!is.matrix(z) || !is.numeric(z)) {
stop("z needs to be a numeric matrix")
}
ncz <- ncol(z)
Expand Down
6 changes: 3 additions & 3 deletions R/scale_brewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' \item{n}{the number of colors in the palette. For a given palette, all combinations of colors are hand picked and not just interpolated between the two extremes. So, even in the same palette, the colors for the different values of \code{n} may be slightly different.}
#' \item{color}{the hex code of the color.}
#' }
#' @source \url{http://colorbrewer2.org}
#' @source \url{https://colorbrewer2.org/}
#' @seealso \code{\link{brewer_info}} for a summary of the properties of colorbrewer palettes.
"brewer"

Expand All @@ -19,7 +19,7 @@
#' \item{name}{the name of the color palette.}
#' \item{maxcolors}{the maximum number of handpicked colors in the palette. (NB: the minimum is always 3).}
#' }
#' @source \url{http://colorbrewer2.org}
#' @source \url{https://colorbrewer2.org/}
#' @seealso \code{\link{brewer}} for a complete table of colorbrewer2 colors.
"brewer_info"

Expand All @@ -33,7 +33,7 @@
#'
#' @family color scales and palettes
#'
#' @references \url{http://colorbrewer2.org}
#' @references \url{https://colorbrewer2.org/}
#' @seealso \code{\link{brewer}} for the colors in the palettes and \code{\link{brewer_info}} for a list of palettes and their characteristics.
#'
#' @examples
Expand Down
2 changes: 1 addition & 1 deletion R/scale_cubehelix.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#'
#' @family color scales and palettes
#'
#' @references \url{https://www.mrao.cam.ac.uk/~dag/CUBEHELIX/}
#' @references \url{https://people.phy.cam.ac.uk/dag9/CUBEHELIX/}
#' @examples
#' # Basic color palettes
#' show_col(
Expand Down
4 changes: 2 additions & 2 deletions R/scale_etopo.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' \item{altitude}{the altitude.}
#' \item{color}{the hex code of the correpsonding color.}
#' }
#' @source \url{http://soliton.vm.bytemark.co.uk/pub/cpt-city/ngdc/tn/ETOPO1.png.index.html}
#' @source \code{http://soliton.vm.bytemark.co.uk/pub/cpt-city/ngdc/tn/ETOPO1.png.index.html}
#' @seealso \code{\link{etopo_scale}} to use the palette.
"etopo"

Expand All @@ -21,7 +21,7 @@
#'
#' @family color scales and palettes
#'
#' @references The topographic colors are based on GMT globe by Lester M. Anderson of CASP, UK, modified by Jesse Varner and Elliot Lim (NOAA/NGDC) to have a smaller band of white at the highest elevations. The bathymetry is based on GMT haxby, popularised by Bill Haxby, LDEO. See \url{https://www.ngdc.noaa.gov/mgg/global/global.html}.
#' @references The topographic colors are based on GMT globe by Lester M. Anderson of CASP, UK, modified by Jesse Varner and Elliot Lim (NOAA/NGDC) to have a smaller band of white at the highest elevations. The bathymetry is based on GMT haxby, popularised by Bill Haxby, LDEO. See \code{https://www.ngdc.noaa.gov/mgg/global/global.html}.
#' @seealso \code{\link{etopo}} for the colors in the palette and the associated altitudes.
#'
#' @export
Expand Down
1 change: 0 additions & 1 deletion R/scale_hue.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,3 @@ scale_fill_hue_d <- function(..., h=c(0,360)+40, c=0.65, l=0.65, reverse=FALSE,
na.value=hue_na(na.value, l=l), guide=guide, ...
)
}

2 changes: 0 additions & 2 deletions R/scale_inferno.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,3 @@ scale_color_inferno <- scale_color_inferno_c
#' @export
#' @usage NULL
scale_colour_inferno <- scale_color_inferno_c


4 changes: 2 additions & 2 deletions R/scale_interp.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ interp_scale <- function(colors=c("white", "black"), model="lab", interp="linear
model <- match.arg(model, c("hcl", "lch", "hsi", "hsl", "hsv", "lab", "rgb", "lrgb"))

interp <- match.arg(interp, c("bezier", "linear"))
if (interp == "bezier" & model != "lab") {
if (interp == "bezier" && model != "lab") {
warning("Bezier interpolation can only be done in L*a*b* space; switching to model=\"lab\".")
model <- "lab"
}
Expand All @@ -139,7 +139,7 @@ interp_scale <- function(colors=c("white", "black"), model="lab", interp="linear
warning("Argument 'values' should not contain missing or non-numeric values. They were removed.")
values <- values[is.finite(values)]
}
if ( ! ( identical(sort(values), values) | identical(sort(values), rev(values)) ) ) {
if ( ! ( identical(sort(values), values) || identical(sort(values), rev(values)) ) ) {
stop("Numbers in 'values' should be monotonously increasing or decreasing.")
}
if ( length(values) != length(colors) ) {
Expand Down
2 changes: 0 additions & 2 deletions R/scale_magma.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,3 @@ scale_color_magma <- scale_color_magma_c
#' @export
#' @usage NULL
scale_colour_magma <- scale_color_magma_c


2 changes: 0 additions & 2 deletions R/scale_plasma.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,3 @@ scale_color_plasma <- scale_color_plasma_c
#' @export
#' @usage NULL
scale_colour_plasma <- scale_color_plasma_c


2 changes: 0 additions & 2 deletions R/scale_turbo.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,3 @@ scale_color_turbo <- scale_color_turbo_c
#' @export
#' @usage NULL
scale_colour_turbo <- scale_color_turbo_c


2 changes: 0 additions & 2 deletions R/scale_viridis.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,3 @@ scale_color_viridis <- scale_color_viridis_c
#' @export
#' @usage NULL
scale_colour_viridis <- scale_color_viridis_c


Loading