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))
}
Run the code above in your browser using DataLab