R/rescaler.R

Defines functions mid_rescaler to_rescaler

# rescaling functions needed for ggplot continuous color scales
# the scales dependency is automatically satisfied when ggplot2 is installed

# returns a rescaling function that scales to a target range
to_rescaler <- function(begin = 0, end = 1) {
  function(x, to = c(begin, end), from = range(x, na.rm = TRUE)) {
    scales::rescale(x, to, from)
  }
}

# returns a rescaling function that scales to a target midpoint
mid_rescaler <- function(mid) {
  function(x, to = c(0, 1), from = range(x, na.rm = TRUE)) {
    scales::rescale_mid(x, to, from, mid)
  }
}

Try the colorspace package in your browser

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

colorspace documentation built on May 2, 2019, 12:49 p.m.