l_tour {loon.tourr} | R Documentation |
Tour in loon
Description
An interactive tour in loon
Usage
l_tour(
data,
scaling = c("data", "variable", "observation", "sphere"),
by = NULL,
on,
as.l_tour = TRUE,
color = loon::l_getOption("color"),
tour_path = tourr::grand_tour(),
group = "color",
start = NULL,
slicing = FALSE,
slicingDistance = NULL,
numOfTours = 30L,
interpolation = 40L,
parent = NULL,
envir = parent.frame(),
...
)
Arguments
data |
a data frame with numerical data only |
scaling |
one of 'variable', 'data', 'observation', 'sphere', or 'none' to specify how the data is scaled. See Details |
by |
loon plot can be separated by some variables into multiple panels.
This argument can take a |
on |
if the |
as.l_tour |
return a |
color |
vector with line colors. Default is given by |
tour_path |
tour path generator, defaults to 2d grand tour |
group |
only used for layers. As we scroll the bar, the layers are re-calculated. This argument is used to specify which state is used to set groups (i.e. "color", "linewidth", etc). |
start |
projection to start at, if not specified, uses default associated with tour path |
slicing |
whether to show a sliced scatter plot |
slicingDistance |
the slicing distance that if the distance between
points and the projected plane is less than this distance, points will be
preserved; else points will be invisible. The default is |
numOfTours |
the number of tours |
interpolation |
the steps between two serial projections. The larger the value is, the smoother the transitions would be. |
parent |
a valid Tk parent widget path. When the parent widget is
specified (i.e. not |
envir |
the |
... |
named arguments to modify the serialaxes states or layouts, see details. |
Details
-
tour_path is a tour generator; available tours are
grand_tour
,dependence_tour
,frozen_tour
,guided_tour
,planned_tour
, and etc -
Argument
as.l_tour
If set to
TRUE
, the function returns anl_tour
(or anl_tour_compound
) object. Essentially, this object is a list with the first element being aloon
(Tcl) widget and the second element a matrix of projection vectors. The advantage of this setup is that the matrix of projection vectors can be easily accessed using the`[`
function (or thel_cget
function). However, a limitation is that it does not constitute a validloon
(Tcl) widget-callingl_isLoonWidget
would returnFALSE
. Consequently, many of loon's functionalities remain inaccessible.If set to
FALSE
, the function returns either aloon
(Tcl) widget (where callingl_isLoonWidget
would returnTRUE
) or anl_compound
object. In this case, the matrix of projection vectors is not directly accessible from it. However, thel_getProjection
function can be used to retrieve an estimated matrix of projection vectors.
-
The
scaling
state defines how the data is scaled. The axes display 0 at one end and 1 at the other. For the following explanation assume that the data is in a n x p dimensional matrix. The scaling options are thenvariable per column scaling observation per row scaling data whole matrix scaling sphere transforming variables to principal components -
The default
slidingDistance
is suggested by Laa, U., Cook, D., & Valencia, G. (2020). First, find the maximum Euclidean distance of each observation (centralized), saymaxD
. Then, compute the "relative volume" thatvRel
= (maxD
^(d - 2))/10, whered
is the dimension of this data set. In the end, the suggestedslidingDistance
is given byvRel
^(1/(d - 2))
Value
an l_tour
or an l_tour_compound
object that
one can query the loon
states and a matrix projection vectors
See Also
Examples
if(interactive() && requireNamespace('tourr')) {
# 2D projection
fl <- tourr::flea[, 1:6]
# different scaling will give very different projections
# in this dataset, scaling 'variable' will give the best separation
p <- l_tour(fl, scaling = 'variable',
color = tourr::flea$species)
l0 <- l_layer_hull(p, group = p["color"],
color = "red", linewidth = 4)
l1 <- l_layer_density2d(p)
# a `l_tour` object
class(p)
# query the matrix of projection vectors
proj <- p['projection'] # or `l_getProjection(p)`
# suppose the scaling is still 'observation'
new_xy <- as.matrix(
loon::l_getScaledData(data = fl,
scaling = 'observation')) %*%
proj
plot(new_xy, xlab = "V1", ylab = "V2",
col = loon::hex12tohex6(p['color']))
# A higher dimension projection
# turn the `tour` to 4 dimensional space
s <- l_tour(fl, color = tourr::flea$species,
scaling = "observation",
tour_path = tourr::grand_tour(4L))
# set `as.l_tour` FALSE
p <- l_tour(fl, scaling = 'observation',
color = tourr::flea$species)
class(p)
## ERROR
## p["projection"]
# query the estimated matrix of projection vectors
l_getProjection(p)
##### facet by region
olive <- tourr::olive
p <- with(olive, l_tour(olive[, -c(1, 2)],
by = region,
color = area))
}