viz_palette: Visualizing CMAP color palettes

View source: R/colors_discrete.R

viz_gradientR Documentation

Visualizing CMAP color palettes

Description

The cmapplot package contains a many color palettes extracted from the larger, official CMAP color palette. Helper functions allow the user to inspect the various palettes before applying them to plots.

Usage

viz_gradient(pal, ttl = NULL)

viz_palette(pal, ttl = NULL, num = NULL)

fetch_pal(
  pal,
  which = c("discrete", "sequential", "divergent"),
  return = c("colors", "type", "exists")
)

Arguments

pal

character, name of a a cmapplot palette, or a vector of colors representing a palette

ttl

character, title to be displayed (the name of the palette)

num

numeric, the number of colors to display

which

a vector of palette types to consider

return

Value to return. "colors", the default, returns the palette as a vector of colors. "type" returns the palette's type. "Exists" returns TRUE or FALSE based on whether the name is found in the palettes table.

Details

Palettes are stored in a tibble the cmapplot_globals environment. The user can access this tibble with get_cmapplot_global, but it is easier to access information about a single palette with fetch_pal.

viz_palette and viz_gradient draw the palette to the plots window. These functions are modified with respect from the ochRe package.

For more information about available cmapplot color palettes and how to apply them, see vignette("colors").

Functions

  • viz_gradient(): Interpolates the range of colors a sequential or divergent palette offers when used on a continuous scale.

  • viz_palette(): Displays the colors of any cmapplot palette

  • fetch_pal(): Returns details about a palette

Examples

# Vizualize a sequential or divergent palette with interpolation
viz_gradient("green_teal_blue")

# Visualize a single palette as individual colors
viz_palette("legislation")

# Print names and types of all available palettes
as.data.frame(get_cmapplot_global("palettes")[1:2])

# Identify the first two colors of the Prosperity Palette
fetch_pal("prosperity")[1:2]

# Confirm that "reds" is a sequential palette
fetch_pal("reds", which = "sequential", return = "exists")


CMAP-REPOS/cmapplot documentation built on March 29, 2025, 11:55 a.m.