Learn R Programming

⚠️There's a newer version (0.3.8) of this package.Take me there.

spinifex

About tours

Data visualization tour is a class of linear projections that are animate small changes in a projection basis over time. Shadows are an example of a 3D object casting a 2D linear projection. Imagine a bar stool cast a circular shadow of its seat. Watching the shadow alone, a rotation of the objection would quickly give structural information about the object; when the legs are rotated into frame you can be more certain the object is a bar stool. In the same way, a tour watches a lower-dimensional projection of the data object. The object permanence of the observations between frames holds structural information that is revealed as the object is rotated.

Scope

Such visualizations are applicable to numeric matrices which could be approximations of component spaces or feature decomposition of non-tabular data. Continuous quantitative variables are preferred, although ordinal discrete variables can also be used. Mapping color and/or shape to a (supervised) class tends to be helpful.

Description

The tourr R package implements grand tours (constrained random walks in the basis), projection pursuit (basis anneals to some objective function), and several other variants and options of visualization tours.

Grand tour

The work and contribution of spinifex are primarily two-fold. The addition of manual tours which allow for user defined (and interactive!) control of the basis. Secondly, a layered API to create tour elements that mirrors the additive creation of ggplot2 visuals. The extension to gganimate and plotly graphics packages, which allow for more control over display and exporting .gif, .mp4, and .html widgets of tours. The later can also consume tours produced in tourr!

We see that bill length is important for separating the orange and green species. Let's change its contribution with a manual tour:

Manual tour

Getting started

library("spinifiex")                      ## Load into session
run_app("radial_tour")                    ## Run a local shiny app, demonstrating radial manual tours
vignette("getting started with spinifex") ## Introduction to tours and spinifex
vignette("ggproto api")                   ## Introduction to the new ggproto api
?ggtour                                   ## Examples and links to ggproto functions
help(package = "spinifex")                ## Review the package contents and documentation

ggproto API

The ggproto API is a layered approach to the composition of animated tours, it should feel similar to the composition of ggplots.

FamilyFunctionRelated toDescription
processingscale_01/sd-scale each column to [01]/std dev away from the mean
processingbasis_pca/olda/...Rdimtools::do.*basis of orthogonal component spaces
processingbasis_half_circle-basis with uniform contribution across half of a circle
processingbasis_guidedtourr::guided_toursilently return the basis from a guided tour
tour pathmanual_tour-basis and interpolation information for a manual tour
tour pathsave_historytourr::save_historysilent extended wrapper returning other tour arrays
displayggtourggplot2::ggplotcanvas and initialization for a tour animation
displayproto_point/textgeom_point/textadds observation points/text
displayproto_density/2dgeom_density/2dadds density curve/2d contours
displayproto_hexgeom_hexadds hexagonal heatmap of observations
displayproto_basis/1d-adds adding basis visual in a unit-circle/-rectangle
displayproto_origin/1d-adds reference mark in the center of the data
displayproto_default/1d-wrapper for proto_* point + basis + origin
displayfacet_wrap_tourggplot2::facet_wrapfacets on the levels of variable
displayappend_fixed_y-add/overwrite a fixed vertical position
animationanimate_plotlyplotly::ggplotlyrender as an interactive hmtl widget
animationanimate_gganimategganimate::animaterender as a .gif .mp4 or other video format
animationfilmstrip-static gpplot faceting on the frames of the animation

Reporting issues

Please submit bug reports, errors, and feature requests to https://github.com/nspyrison/spinifex/issues

Copy Link

Version

Install

install.packages('spinifex')

Monthly Downloads

274

Version

0.3.2

License

CC BY-NC-SA 4.0

Issues

Pull Requests

Stars

Forks

Maintainer

Nicholas Spyrison

Last Published

January 4th, 2022

Functions in spinifex (0.3.2)

animate_plotly

Animate a ggtour as and HTML widget via {plotly}
array2df

Turns a tour path array into a long data frame.
basis_half_circle

Create a basis that gives uniform contribution in a circle
PimaIndiansDiabetes_wide

Pima Indians Diabetes Dataset, wide
basis_guided

Solve for the last basis of a guided tour.
append_fixed_y

Append a fixed vertical height
basis_pca

The basis of Principal Component Analysis (PCA)
animate_gganimate

Animate a ggtour as a .gif via {gganimate}
BreastCancer

Wisconsin Breast Cancer Database
PimaIndiansDiabetes_long

Pima Indians Diabetes Dataset, long
draw_basis

Draw a basis on a static ggplot
map_absolute

Manually offset and scale the first 2 columns of a matrix or data.frame.
proto_hline0

Tour proto adding a vertical/horizontal line
manual_tour

Produce the series of projection bases to rotate a variable into and out of a projection.
proto_text

Tour proto for data, text labels
proto_highlight

Tour proto highlighing specified points
devMessage

Development message
.bind_elements2df

Binds replicated elements of a list as columns of a data frame.
basis_olda

The basis of Orthogonal Linear Discriminant Analysis (OLDA)
basis_onpp

The basis of Orthogonal Neighborhood Preserving Projection (OLPP)
create_manip_space

Create a manipulation space to rotate the manipulation variable in.
.init4proto

Initialize common obj from .global ggtour() objects & test their existence
facet_wrap_tour

Wrap a 1d ribbon of panels into 2d for animation
proto_default

Wrapper function for default 2D/1D tours respectively.
penguins

Size measurements for adult foraging penguins near Palmer Station, Antarctica
proto_basis

Tour proto for a 2D and 1D basis axes respectively
map_relative

Returns the axis scale and position.
proto_density

Tour proto for data, 1D density, with rug marks
filmstrip

Create a "filmstrip" of the frames of a ggtour.
ggtour

Prepare a new grammar of graphics tour
spinifex

spinifex
proto_density2d

Tour proto for data, 1D density, with rug marks
.lapply_rep_len

Replicate all vector elements of a list
proto_origin

Tour proto for data origin zero mark
is_orthonormal

Orthonormality of a matrix
play_manual_tour

Animate a manual tour. superseded
interpolate_manual_tour

Interpolates a manual tour
play_tour_path

Animates the provided tour path.
view_frame

Plot a single frame of a manual tour.
view_manip_space

Plot 2D projection frame and return the axes table.
proto_point

Tour proto for data point
theme_spinifex

A ggplot2 theme suggested for linear projections with spinifex. The default theme in spinifex functions.
last_ggtour

Retrieve/set a list from the last ggtour(), required for the use of proto_* functions.
manip_var_of

Suggest a manipulation variable.
run_app

Runs a shiny app demonstrating manual tours
rotate_manip_space

Performs a rotation on the manipulation space of the given manip var.
scale_sd

Preprocess numeric variables
scale_axes

Deprecated functions in package spinifex.
save_history

Save a tour basis array.
scale_colour_discrete

Set default color & fill for discrete variables
proto_frame_cor2

Tour proto for frames square correlation
weather

Sample dataset of daily weather observations from Canberra airport in Australia.
render_

Prepare the ggplot object before passing to either animation package.
wine

The wine dataset from the UCI Machine Learning Repository.
proto_hex

Tour proto for data, hexagonal heatmap
render_gganimate

Render the frames as a gganimate animation.
render_plotly

Animation the frames as a HTML widget.
basis_odp

The basis of Orthogonal Discriminant Projection (ODP)