R/colormaps.R

Defines functions colormap_table colormap_colours vol_colormaps

Documented in vol_colormaps

# ============================ #
# Colour tables                #
# ============================ #

#' Colour tables the renderer carries
#'
#' @title Colour tables the renderer carries
#' @description Names the perceptually uniform colour tables that the payload
#'   writes into its lookup image and that the viewer offers in its menu.
#' @return A character vector of table names, in the order the viewer lists
#'   them.
#' @details The tables are the oceanographic set of Thyng et al. (2016), stored
#'   in the package as 256 sampled colours each so that a payload is written
#'   without the \pkg{cmocean} package installed. `matter` runs from pale cream
#'   through orange to dark purple and suits a positive, strongly skewed field;
#'   `thermal` and `haline` are the temperature and salinity tables; `deep` and
#'   `dense` reverse the light and dark ends, which matters when the background
#'   is white.
#' @references Thyng, K. M., Greene, C. A., Hetland, R. D., Zimmerle, H. M., &
#'   DiMarco, S. F. (2016). True colors of oceanography: guidelines for effective
#'   and accurate colormap selection. *Oceanography*, 29(3), 9-13.
#'   \doi{10.5670/oceanog.2016.66}
#' @examples
#' vol_colormaps()
#' @seealso [vol_payload()], which writes these into the payload,
#'   [plot.vol_field()], which uses one of them, and [vol_widget()], whose
#'   `cmap` option selects one by position.
#' @export
vol_colormaps <- function() dimnames(VOLUMR_CMAPS)[[1]]

# The 256 colours of one table, as hex strings, for a plot outside the browser.
#' @noRd
colormap_colours <- function(name = "matter") {
    name <- match.arg(name, vol_colormaps())
    m <- VOLUMR_CMAPS[name, , ]
    grDevices::rgb(m[, 1], m[, 2], m[, 3], maxColorValue = 255)
}

# The lookup image the payload carries: one row of 256 colours per table.
#' @noRd
colormap_table <- function() VOLUMR_CMAPS

Try the volumr package in your browser

Any scripts or data that you put into this service are public.

volumr documentation built on Dec. 2, 2026, 5:07 p.m.