View source: R/colors_discrete.R
viz_gradient | R Documentation |
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.
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")
)
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. |
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")
.
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
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.