Title: | Portable and Performant Tour Animations |
---|---|
Description: | Provides 2D and 3D tour animations as HTML widgets. The user can interact with the widgets using orbit controls, tooltips, brushing, and timeline controls. Linked brushing is supported using 'crosstalk', and widgets can be embedded in Shiny apps or HTML documents. |
Authors: | Casper Hart [aut, cre],
Earo Wang [aut, ths] |
Maintainer: | Casper Hart <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-02-25 02:45:13 UTC |
Source: | https://github.com/casperhart/detourr |
This function initialises a detour
object which, along with the
tour_path
and show_functions
is used to build a detour visualisation.
detour(.data, mapping)
detour(.data, mapping)
.data |
a data frame, tibble, or crosstalk::SharedData object |
mapping |
a mapping of data columns to aesthetic values using the
|
A detour
object containing information about the tour path and
its parameters
detour(tourr::flea, tour_aes(projection = -species, colour = species)) |> tour_path(grand_tour(3), fps = 60) |> show_scatter(alpha = 0.7, axes = FALSE)
detour(tourr::flea, tour_aes(projection = -species, colour = species)) |> tour_path(grand_tour(3), fps = 60) |> show_scatter(alpha = 0.7, axes = FALSE)
Output and render functions for using detourr with shiny. The output function used must match both the display method and tour dim used, or it will lead to strange behavour.
displayScatter3dOutput(output_id, width = "100%", height = "400px") displayScatter2dOutput(output_id, width = "100%", height = "400px") shinyRenderDisplayScatter2d(expr, env = parent.frame(), quoted = FALSE) shinyRenderDisplayScatter3d(expr, env = parent.frame(), quoted = FALSE)
displayScatter3dOutput(output_id, width = "100%", height = "400px") displayScatter2dOutput(output_id, width = "100%", height = "400px") shinyRenderDisplayScatter2d(expr, env = parent.frame(), quoted = FALSE) shinyRenderDisplayScatter3d(expr, env = parent.frame(), quoted = FALSE)
output_id |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
an expression that generates a detourr widget |
env |
The environment in which to evaluate |
quoted |
Is |
An output or render function that enables the use of the widget within shiny applications
Test for detour-ness
is_detour(x)
is_detour(x)
x |
an object |
TRUE or FALSE
Two datasets are available; mnist_embeddings_8d
contains 8-dimensional
embedding vectors and mnist_embeddings_32d
contains 32-dimensional
embedding vectors.
The neural network that produced these embeddings was created using TensorFlow (Abadi et al. (2016)) with a variation of the code found in this example: https://www.tensorflow.org/addons/tutorials/losses_triplet
mnist_embeddings_32d mnist_embeddings_8d
mnist_embeddings_32d mnist_embeddings_8d
An object of class tbl_df
(inherits from tbl
, data.frame
) with 10000 rows and 34 columns.
An object of class tbl_df
(inherits from tbl
, data.frame
) with 10000 rows and 10 columns.
A data frame with 10,000 rows and p variables:
id: sequential ID or row number of the image
label: the digit 0, 1, ..., 9
X1–Xp: elements 1–p of the embedding vector
LeCun, Y (1998). The MNIST database of handwritten digits. http://yann.lecun.com/exdb/mnist/.
Abadi, M, P Barham, J Chen, Z Chen, A Davis, J Dean, M Devin, S Ghemawat, G Irving, M Isard, et al. (2016). TensorFlow: A System for Large-Scale Machine Learning. In: 12th USENIX symposium on operating systems design and implementation (OSDI 16), pp.265–283.
An implementation of the Sage Tour described in Laa et al., 2021. It uses a radial transformation on the projected data so that the relative volume is preserved when the data is projected. I.e. a uniform distribution in the original space will remain uniformly distributed in the projected space. Includes both 2D and 3D variations.
show_sage( x, ..., palette = viridis, center = TRUE, axes = TRUE, edges = NULL, paused = TRUE, scale_factor = NULL, gamma = 1, R = NULL )
show_sage( x, ..., palette = viridis, center = TRUE, axes = TRUE, edges = NULL, paused = TRUE, scale_factor = NULL, gamma = 1, R = NULL )
x |
a |
... |
used to support aesthetic parameters for the plot, including
|
palette |
Colour palette to use with the colour aesthetic. Can be:
|
center |
If TRUE, center the projected data to (0, 0, 0). |
axes |
Can be one of:
|
edges |
A two column numeric matrix giving indices of ends of lines. |
paused |
whether the widget should be initialised in the 'paused' state |
scale_factor |
used as a multiplier for the point coordinates so they are displayed on a sensible range. Defaults to the reciprocal of maximum distance from a point to the origin. |
gamma |
the gamma parameter for scaling the effective dimensionality for the sage tour radial transformation. defaults to 1 |
R |
scale for the radial transformation. Defaults to |
This display method produces an interactive scatterplot animation which supports both 2D and 3D tours. Linked selection and filtering is also supported using crosstalk. The set of interactive controls available are:
A timeline with a play / pause button and indicators at the position of each basis used. The basis indicators can be hovered with the mouse to show the index of the basis, or clicked to jump to that basis. The timeline also allows for clicking and dragging of the scrubber to move to any individual frame of the animation.
Orbit controls. For the 2D variant, this allows the projection to be rotated by clicking and dragging from left to right. For the 3D variant, full orbit controls are available by clicking and dragging. For both orbit and pan controls, the scroll wheel can be used to zoom.
Pan controls, which work similarly to orbit controls but move the camera laterally / vertically rather than rotating
Resetting of the orbit and pan controls
Selection and highlighting. Multiple selection is possible by using the shift key
Colouring / brushing of highlighted points
An object of class htmlwidget
Laa, U., Cook, D., & Lee, S. (2021). Burning sage: Reversing the curse of dimensionality in the visualization of high-dimensional data. Journal of Computational and Graphical Statistics, 1-10.
show_scatter
detour(tourr::flea, tour_aes(projection = -species, colour = species)) |> tour_path(grand_tour(3), fps = 60) |> show_sage(gamma = 2)
detour(tourr::flea, tour_aes(projection = -species, colour = species)) |> tour_path(grand_tour(3), fps = 60) |> show_sage(gamma = 2)
Display method for a high performance 2D or 3D scatter plot. Performance is achieved through the use of Three.js / WebGL, and the 2D or 3D variant is selected automatically based on the tour generator provided.
show_scatter( x, ..., palette = viridis, center = TRUE, axes = TRUE, edges = NULL, paused = TRUE, scale_factor = NULL )
show_scatter( x, ..., palette = viridis, center = TRUE, axes = TRUE, edges = NULL, paused = TRUE, scale_factor = NULL )
x |
a |
... |
used to support aesthetic parameters for the plot, including
|
palette |
Colour palette to use with the colour aesthetic. Can be:
|
center |
If TRUE, center the projected data to (0, 0, 0). |
axes |
Can be one of:
|
edges |
A two column numeric matrix giving indices of ends of lines. |
paused |
whether the widget should be initialised in the 'paused' state |
scale_factor |
used as a multiplier for the point coordinates so they are displayed on a sensible range. Defaults to the reciprocal of maximum distance from a point to the origin. |
This display method produces an interactive scatterplot animation which supports both 2D and 3D tours. Linked selection and filtering is also supported using crosstalk. The set of interactive controls available are:
A timeline with a play / pause button and indicators at the position of each basis used. The basis indicators can be hovered with the mouse to show the index of the basis, or clicked to jump to that basis. The timeline also allows for clicking and dragging of the scrubber to move to any individual frame of the animation.
Orbit controls. For the 2D variant, this allows the projection to be rotated by clicking and dragging from left to right. For the 3D variant, full orbit controls are available by clicking and dragging. For both orbit and pan controls, the scroll wheel can be used to zoom.
Pan controls, which work similarly to orbit controls but move the camera laterally / vertically rather than rotating
Resetting of the orbit and pan controls
Selection and highlighting. Multiple selection is possible by using the shift key
Colouring / brushing of highlighted points
An object of class htmlwidget
detour(tourr::flea, tour_aes(projection = -species, colour = species)) |> tour_path(grand_tour(3), fps = 60) |> show_scatter(alpha = 0.7, axes = FALSE)
detour(tourr::flea, tour_aes(projection = -species, colour = species)) |> tour_path(grand_tour(3), fps = 60) |> show_scatter(alpha = 0.7, axes = FALSE)
Internal method for 2D and 3D Scatter Plot Display
show_scatter_internal( x, ..., palette = viridisLite::viridis, center = TRUE, axes = TRUE, edges = NULL, paused = TRUE, scale_factor = NULL )
show_scatter_internal( x, ..., palette = viridisLite::viridis, center = TRUE, axes = TRUE, edges = NULL, paused = TRUE, scale_factor = NULL )
x |
a |
... |
used to support aesthetic parameters for the plot, including
|
palette |
Colour palette to use with the colour aesthetic. Can be:
|
center |
If TRUE, center the projected data to (0, 0, 0). |
axes |
Can be one of:
|
edges |
A two column numeric matrix giving indices of ends of lines. |
paused |
whether the widget should be initialised in the 'paused' state |
scale_factor |
used as a multiplier for the point coordinates so they are displayed on a sensible range. Defaults to the reciprocal of maximum distance from a point to the origin. |
This display method produces an interactive scatterplot animation which supports both 2D and 3D tours. Linked selection and filtering is also supported using crosstalk. The set of interactive controls available are:
A timeline with a play / pause button and indicators at the position of each basis used. The basis indicators can be hovered with the mouse to show the index of the basis, or clicked to jump to that basis. The timeline also allows for clicking and dragging of the scrubber to move to any individual frame of the animation.
Orbit controls. For the 2D variant, this allows the projection to be rotated by clicking and dragging from left to right. For the 3D variant, full orbit controls are available by clicking and dragging. For both orbit and pan controls, the scroll wheel can be used to zoom.
Pan controls, which work similarly to orbit controls but move the camera laterally / vertically rather than rotating
Resetting of the orbit and pan controls
Selection and highlighting. Multiple selection is possible by using the shift key
Colouring / brushing of highlighted points
An object of class htmlwidget
An implementation of the Slice Tour described in Laa et al., 2020. Points close to the projection plane are highlighted, and those far away are faded out.
show_slice( x, ..., palette = viridis, center = TRUE, axes = TRUE, edges = NULL, paused = TRUE, scale_factor = NULL, slice_relative_volume = 0.1, anchor = NULL )
show_slice( x, ..., palette = viridis, center = TRUE, axes = TRUE, edges = NULL, paused = TRUE, scale_factor = NULL, slice_relative_volume = 0.1, anchor = NULL )
x |
a |
... |
used to support aesthetic parameters for the plot, including
|
palette |
Colour palette to use with the colour aesthetic. Can be:
|
center |
If TRUE, center the projected data to (0, 0, 0). |
axes |
Can be one of:
|
edges |
A two column numeric matrix giving indices of ends of lines. |
paused |
whether the widget should be initialised in the 'paused' state |
scale_factor |
used as a multiplier for the point coordinates so they are displayed on a sensible range. Defaults to the reciprocal of maximum distance from a point to the origin. |
slice_relative_volume |
number default 0.1. Controls the relative volume of the slice and thus the number of points which are highlighted. This is an approximate value and is only accurate for values << 1 |
anchor |
anchor vector of length p to offset the projection plane when calculating the distance from each point to the projection plane. |
This display method produces an interactive scatterplot animation which supports both 2D and 3D tours. Linked selection and filtering is also supported using crosstalk. The set of interactive controls available are:
A timeline with a play / pause button and indicators at the position of each basis used. The basis indicators can be hovered with the mouse to show the index of the basis, or clicked to jump to that basis. The timeline also allows for clicking and dragging of the scrubber to move to any individual frame of the animation.
Orbit controls. For the 2D variant, this allows the projection to be rotated by clicking and dragging from left to right. For the 3D variant, full orbit controls are available by clicking and dragging. For both orbit and pan controls, the scroll wheel can be used to zoom.
Pan controls, which work similarly to orbit controls but move the camera laterally / vertically rather than rotating
Resetting of the orbit and pan controls
Selection and highlighting. Multiple selection is possible by using the shift key
Colouring / brushing of highlighted points
An object of class htmlwidget
Laa, U., Cook, D., & Valencia, G. (2020). A slice tour for finding hollowness in high-dimensional data. Journal of Computational and Graphical Statistics, 29(3), 681-687.
show_scatter
x <- geozoo::torus(p = 4, n = 10000)$points |> tibble::as_tibble(.name_repair = "unique") detour(x, tour_aes(projection = everything())) |> tour_path(grand_tour(2)) |> show_slice(slice_relative_volume = 0.1)
x <- geozoo::torus(p = 4, n = 10000)$points |> tibble::as_tibble(.name_repair = "unique") detour(x, tour_aes(projection = everything())) |> tour_path(grand_tour(2)) |> show_slice(slice_relative_volume = 0.1)
Aesthetic mapping for tours describing how variables in the data are mapped to visual properties of the tour animation.
tour_aes(...)
tour_aes(...)
... |
list of name-value pairs in the form 'aesthetic = variable'. Variables are evaluated using tidyselect syntax. |
a list of quosures
detour(tourr::flea, tour_aes(projection = -species, colour = species)) |> tour_path(grand_tour(3), fps = 60) |> show_scatter(alpha = 0.7, axes = FALSE)
detour(tourr::flea, tour_aes(projection = -species, colour = species)) |> tour_path(grand_tour(3), fps = 60) |> show_scatter(alpha = 0.7, axes = FALSE)
This function takes a detour
object as an input, and generates a
sequence of projection matrices for the tour. The return value is another
detour
object with the tour path and other metadata attached. This can
then be passed to a show_*
#' function to generate the detour
visualisation.
tour_path( x, tour_path = grand_tour(2), start = NULL, aps = 1, fps = 30, max_bases = 10 )
tour_path( x, tour_path = grand_tour(2), start = NULL, aps = 1, fps = 30, max_bases = 10 )
x |
a |
tour_path |
tour path generator, defaults to 2d grand tour |
start |
projection to start at, if not specified, uses default associated with tour path |
aps |
target angular velocity (in radians per second) |
fps |
target frames per second |
max_bases |
the maximum number of bases to generate |
A detour
object containing information about the tour path and
its parameters