R/dt_rescale.R

Defines functions dt_rescale

Documented in dt_rescale

#' Rescale variables to common scale
#'
#' Purely for visualization purposes.
#'
#' When you want your plots to share a single legend without
#' washing out the variance, you have to rescale the variables.
#' Code borrowed from this \href{https://gis.stackexchange.com/questions/194814/rescale-raster-in-r}{stackexchange}.
#'
#' @param x \code{vector} of numeric values
#' @param new.min \code{numeric}, lower bound for rescale
#' @param new.max \code{numeric}, upper bound for rescale
#' @param na.rm \code{logical}, whether to ignore NA values
#'
#' @return \code{vector}
#' @export
#'
#' @examples
#'
dt_rescale <- function(x, new.min = -3, new.max = 3, na.rm = TRUE) {

  x.min = min(x, na.rm = na.rm)
  x.max = max(x, na.rm = na.rm)

  new.min + (x - x.min) * ((new.max - new.min) / (x.max - x.min))

}
kbvernon/deseRt documentation built on May 27, 2020, 11:44 p.m.