scaleWithin: Scale a set of values

View source: R/scaleWithin.R

scaleWithinR Documentation

Scale a set of values

Description

This function maps a set of values to a range of integers (from 1 to a positive integer passed as an argument).

Usage

scaleWithin(x, n = 100, mn = min(x), mx = max(x))

Arguments

x

a numeric object of type numeric or coercible as one.

n

an integer designing The number of scaled values (between 1 and n).

mn

minimum value (mn and lower values are set to 1).

mx

maximum value (mx and higher values are set to n).

Details

This function was originally created to ease the creation of custom color scales. In such context, it is common practice to define a minium and a maximum for the set of values to be displayed values as well as a number of color to be used in the color scale (n). This is exactly what scaleWithin() does: minimum and maximum are by default the ones of the set of values x but can also be set using mn and mx in which case values below mn will be set to mn (and thus to 1 in the output) and values above mx will be set to mx (and thus to 1 in the output). Finally, the number of colors to be used used in is given by n.

Value

A numeric vector

Examples

x <- stats::rpois(20, 20)
scaleWithin(x, 20, 10, 30)
scaleWithin(matrix(x, 10, 2), mn = 20, mx = 30)

inSileco/inSilecoMisc documentation built on Sept. 14, 2022, 5:44 a.m.