l_scale3D {loon} | R Documentation |
Scale for 3d plotting
Description
l_scale3D
scales its argument in a variety of ways
used for 3D visualization.
Usage
l_scale3D(x, center = TRUE, method = c("box", "sphere"))
Arguments
x |
the matrix or data.frame whose columns are to be scaled.
Any |
center |
either a logical value or numeric-alike vector of length equal
to the number of columns of |
method |
the scaling method to use.
If |
Value
a data.frame whose columns are centred and scaled according to
the given arguments. For method = "sphere")
, the three variable names are
x1
, x2
, and x3
.
See Also
Other three-dimensional plotting functions:
l_plot3D()
Examples
##### Iris data
#
# All variables (including Species as a factor)
result_box <- l_scale3D(iris)
head(result_box, n = 3)
apply(result_box, 2, FUN = range)
# Note mean is not zero.
apply(result_box, 2, FUN = mean)
# Sphering only on 3D data.
result_sphere <- l_scale3D(iris[, 1:3], method = "sphere")
head(result_sphere, n = 3)
apply(result_sphere, 2, FUN = range)
# Note mean is numerically zero.
apply(result_sphere, 2, FUN = mean)
# With NAs
x <- iris
x[c(1, 3), 1] <- NA
x[2, 3] <- NA
result_box <- l_scale3D(x)
head(result_box, n = 5)
apply(result_box, 2, FUN = function(x) {range(x, na.rm = TRUE)})
# Sphering only on 3D data.
result_sphere <- l_scale3D(x[, 1:3], method = "sphere")
# Rows having had any NA are all NA after sphering.
head(result_sphere, n = 5)
# Note with NAs mean is no longer numerically zero.
# because centring was based on all non-NAs in each column
apply(result_sphere, 2, FUN = function(x) {mean(x, na.rm = TRUE)})