scale_free {plothelper} | R Documentation |
Scale values into a Certain Location
Description
A simple function to put numeric values into a certain interval. Suppose you have 20, 60, 80, 100, and you want them to be in the interval of [0, 1], so you can get 0, 0.5, 0.75, 1.
Usage
scale_free(
x,
left = 0,
right = 1,
reverse = FALSE,
xmin = NULL,
xmax = NULL,
na.rm = FALSE
)
Arguments
x |
a numeric vector or a numeric matrix, data frame, tibble object. |
left |
the smallest value of the the interval.
If |
right |
the largest value of the the interval.
If |
reverse |
whether to assign values in a
reverse way. Default is FALSE.
If |
xmin |
the min value. Default is NULL,
which means use the min value of |
xmax |
the same meaning as |
na.rm |
used by |
Examples
y=scale_free(c(-1, 0, 2))
y=scale_free(c(-1, 0, 2), rev=TRUE)
#
# x is a data frame.
x=data.frame(
c(-1, 0, 0, 0, 2), c(-1, 0, 0, 0, 2),
c(-2, 0, 2, 4, 6), c(-2, 0, 2, 4, 6)
)
y=scale_free(x,
left=0, right=10,
reverse=c(FALSE, TRUE, FALSE, TRUE)
)
y=scale_free(x,
left=c(0, 0, 100, 100), right=c(10, 100, 200, 200),
reverse=c(FALSE, TRUE, FALSE, TRUE)
)