Skip to contents

Creates a threshold scale, where threshold breaks are computed from the given quantile probs.

Quantile scale legend ticks will be quantile values at each quantile break (including limits), not the quantile probabilities at each break. This can be overridden in tick_format.

Example: tick_format = function(x) as.character(probs).

Usage

scale_color_quantile(
  col,
  palette = scales::viridis_pal(),
  na_color = "#000000",
  probs = seq.int(0, 1, 0.25),
  data = NULL,
  tick_format = format_number,
  col_label = "{.col}",
  legend = TRUE
)

scale_quantile(
  col,
  range = 0:1,
  na_value = 0,
  probs = seq.int(0, 1, 0.25),
  data = NULL,
  col_label = "{.col}",
  legend = TRUE
)

Arguments

col

<name | string> The name of the column containing data to be scaled. Must be a valid input to rlang::ensym(); either a named column (non-standard evaluation), a string. Supports tidy-eval.

palette

<color|function> The colour palette of the colour scale. Must be a:

  • vector of RGBA hex colours,

  • a palette generator function, taking a length parameter, or

  • a palette ramp created from scales::colour_ramp()

A scales::colour_ramp() interpolator is created from the input palette.

na_color

<color> The colour value for NA input values.

probs

<numeric> The quantile probabilities. Must be between 0 and 1.

data

<numeric> The data used to compute the quantiles. If NULL, will be taken from the layer data.

tick_format

<function> A label function taking a vector of ticks returning formatted ticks.

col_label

<string | function> A template string or a label function for customising the column name in the legend.

  • if col_label is a string, {.col} may be used to represent the col name

  • if col_label is a function, the function must take a single argument: the col name

legend

<boolean> Indicate whether the legend should be displayed for this scale.

range

<numeric> The output range of the numeric scale. Must be length >= 2. A stats::approxfun() interpolator is created from the input range.

na_value

<number> The output value for NA input values.

Note

As the quantiles are computed from input data, quantile scales are incompatible with layers that load data from a url (e.g mvt_layer). If quantiles for remote data are known, a quantile scale can be constructed manually with scale_threshold().