Learn R Programming

oce (version 0.2-1)

rescale: Rescale values to lie in a given range

Description

Rescale values to lie in a given range

Usage

rescale(x, xlow, xhigh, rlow=0, rhigh=1, clip=TRUE)

Arguments

x
a numeric vector.
xlow
x value to correspond to rlow. If not given, it will be calculated as the minimum value of x
xhigh
x value to correspond to rhigh. If not given, it will be calculated as the maximum value of x
rlow
value of the result corresponding to x equal to xlow.
rhigh
value of the result corresponding to x equal to xhigh.
clip
logical, set to TRUE to clip the result to the range rlow to rhigh.

Value

  • A new vector, which has minimum lim[1] and maximum lim[2].

Details

This is helpful in e.g. developing a color scale for an image plot.

Examples

Run this code
x <- runif(1000, min=-1, max=1)
y <- runif(1000, min=-1, max=1)
drawpalette(zlim=c(0,2), zlab=expression(x^2+y^2), col=oceColorsJet)
col <- oceColorsJet(256)[rescale(x^2+y^2, rlow=1, rhigh=256)]
plot(x, y, col=col, cex=4, pch=20)

Run the code above in your browser using DataLab