palette_color_continuous: Color Mapping (continuous)

View source: R/palettes.R

palette_color_continuousR Documentation

Color Mapping (continuous)

Description

Maps continuous values to an interpolated colors gradient.

Usage

palette_color_continuous(
  colors = NULL,
  domain = NULL,
  midpoint = NULL,
  missing = "#DDDDDD"
)

palette_colour_continuous(
  colors = NULL,
  domain = NULL,
  midpoint = NULL,
  missing = "#DDDDDD"
)

Arguments

colors

A vector of colors or a function that when called with a single argument (an integer specifying the number of colors) returns a vector of colors. If NULL (the default), uses YlOrRd.

domain

A numeric range specifying the possible values that can be mapped.

midpoint

A length-one numeric vector specifying the mid-point of input range.

missing

The color to return for NA values.

Value

A palette function that when called with a single argument (a numeric vector of continuous values) returns a character vector of colors.

See Also

grDevices::colorRamp()

Other palettes: palette_color_discrete(), palette_color_picker(), palette_shape(), palette_size

Examples

## Visualize a simple DEM model
## Distribution of elevation values
elevation <- hist(volcano)

## Where are breaks?
elevation$breaks

## Build palette functions
BuRd <- color("BuRd")
ramp_BuRd <- palette_color_continuous(colors = BuRd(10))

## Plot image
image(volcano, col = ramp_BuRd(elevation$breaks))
legend("topright", legend = elevation$breaks, fill = ramp_BuRd(elevation$breaks))

## Scatter plot
## Build color palette functions
YlOrBr <- color("YlOrBr")
pal_color <- palette_color_continuous(colors = YlOrBr)

## Build symbol palette functions
pal_size <- palette_size_sequential(range = c(1, 3))

## Plot
plot(
  x = iris$Petal.Length,
  y = iris$Sepal.Length,
  pch = 16,
  col = pal_color(iris$Petal.Length),
  cex = pal_size(iris$Petal.Length),
  xlab = "Petal length",
  ylab = "Sepal length",
  panel.first = grid(),
  las = 1
)

khroma documentation built on April 4, 2025, 2:37 a.m.