scaleWithin | R Documentation |
This function maps a set of values to a range of integers (from 1 to a positive integer passed as an argument).
scaleWithin(x, n = 100, mn = min(x), mx = max(x))
x |
a numeric object of type |
n |
an integer designing The number of scaled values (between 1 and |
mn |
minimum value ( |
mx |
maximum value ( |
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
.
A numeric vector
x <- stats::rpois(20, 20) scaleWithin(x, 20, 10, 30) scaleWithin(matrix(x, 10, 2), mn = 20, mx = 30)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.