Learn R Programming

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

#install.packages("spinifex")             ## Install from CRAN
library("spinifex")                       ## Load into session
run_app("radial_tour")                    ## Run a local shiny app, showing radial 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 html 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

302

Version

0.3.10

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Nicholas Spyrison

Last Published

September 18th, 2025

Functions in spinifex (0.3.10)

array2df

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

Suggest a manipulation variable.
last_ggtour_env

Retrieve/set last ggtour() information
is_any_layer_class

Check ggplot layers for use of a specific geom
is_orthonormal

Orthonormality of a matrix
proto_density

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

Returns the axis scale and position.
render_plotly

Animation the frames as a HTML widget.
proto_density2d

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

Tour proto for data origin zero mark
play_manual_tour

Animate a manual tour. superseded
ide

Intrinsic dimension estimation (ide).
interpolate_manual_tour

Interpolates a manual tour
proto_point

Tour proto for data point
play_tour_path

Animates the provided tour path.
scale_colour_discrete

Set default color & fill for discrete variables
proto_highlight

Tour proto highlighing specified points
scale_sd

Preprocess numeric variables
proto_hline0

Tour proto adding a vertical/horizontal line
plot_pca_scree

Plot 2 components of Principal Component Analysis
manual_tour

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

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

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

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

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

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

Plot 2 components of Principal Component Analysis
proto_hex

Tour proto for data, hexagonal heatmap
proto_frame_cor2

Tour proto for frames square correlation
theme_spinifex

Theme spinifex
render_gganimate

Render the frames as a gganimate animation.
run_app

Runs a shiny app demonstrating manual tours
view_frame

Plot a single frame of a manual tour.
save_history

Save a tour basis array.
proto_text

Tour proto for data, text labels
view_manip_space

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

Tour proto for data, text labels that repel
penguins_na.rm

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

spinifex
wine

The wine dataset from the UCI Machine Learning Repository.
scale_axes

Deprecated functions in package spinifex.
weather

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

The basis of Orthogonal Discriminant Projection (ODP)
PimaIndiansDiabetes_long

Pima Indians Diabetes Dataset, long
animate_plotly

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

Append a fixed vertical height
BreastCancer_na.rm

Wisconsin Breast Cancer Database
basis_guided

Solve for the last basis of a guided tour.
basis_half_circle

Create a basis that gives uniform contribution in a circle
animate_gganimate

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

The basis of Orthogonal Neighborhood Preserving Projection (ONPP)
basis_olda

The basis of Orthogonal Linear Discriminant Analysis (OLDA)
facet_wrap_tour

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

Draw a basis on a static ggplot
basis_pca

The basis of Principal Component Analysis (PCA)
.lapply_rep_len

Replicate all vector elements of a list
create_manip_space

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

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

Pima Indians Diabetes Dataset, wide
ggtour

Prepare a new grammar of graphics tour
filmstrip

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

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

Development message