## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = TRUE
)
library(tourr)

## ----grand, eval = FALSE------------------------------------------------------
# # 2D projections — the default
# f <- flea[,1:6] # For convenience
# animate_xy(f)
# 
# # 1D projections shown as a density
# animate_dist(f)

## ----guided, eval = FALSE-----------------------------------------------------
# # Find cluster structure without class labels
# animate_xy(f, tour_path = guided_tour(holes()))
# 
# # Same search, colour by known species once structure is found
# animate_xy(f,
#   tour_path = guided_tour(holes()),
#   col = flea$species
# )
# 
# # Use class labels directly to separate groups
# animate_xy(f,
#   tour_path = guided_tour(lda_pp(flea$species)),
#   col = flea$species
# )

## ----little, eval = FALSE-----------------------------------------------------
# animate_xy(f, tour_path = little_tour())

## ----planned, eval = FALSE----------------------------------------------------
# # Save a grand tour path
# set.seed(42)
# t1 <- save_history(f, max = 10)
# 
# # Replay it in a scatterplot
# animate_xy(f, tour_path = planned_tour(t1))
# 
# # Replay the same path with species colour added
# animate_xy(f,
#   tour_path = planned_tour(t1),
#   col = flea$species
# )
# 
# # Cycle continuously through the saved bases
# animate_xy(f, tour_path = planned_tour(t1, cycle = TRUE))

## ----local, eval = FALSE------------------------------------------------------
# # Start from a specific projection (e.g. one saved from a guided tour)
# start <- basis_random(6, 2)
# 
# # Explore a small neighbourhood of angle pi/4
# animate_xy(f,
#   tour_path = local_tour(start, angle = pi / 4),
#   col = flea$species
# )

## ----radial, eval = FALSE-----------------------------------------------------
# # Use a saved projection as the starting point — here we take the
# # end-point of a guided tour run with holes()
# set.seed(42)
# guided_path  <- save_history(f, guided_tour(holes()), sphere = TRUE)
# start        <- matrix(guided_path[, , dim(guided_path)[3]], nrow = 6)
# 
# # Rotate variable 4 (elytra width) out and back in
# animate_xy(f,
#   tour_path = radial_tour(start, mvar = 4),
#   col = flea$species,
#   rescale = TRUE
# )
# 
# # Rotate two variables simultaneously to see their joint contribution
# animate_xy(f,
#   tour_path = radial_tour(start, mvar = c(3, 4)),
#   col = flea$species,
#   rescale = TRUE
# )

## ----radial-1d, eval = FALSE--------------------------------------------------
# start1d <- basis_random(6, 1)
# animate_dist(f, radial_tour(start1d, mvar = 2), rescale = TRUE)

## ----frozen, eval = FALSE-----------------------------------------------------
# # Fix variable 3 to contribute equally to both axes
# frozen      <- matrix(NA, nrow = 6, ncol = 2)
# frozen[3, ] <- 0.5
# 
# animate_xy(f, tour_path = frozen_tour(2, frozen))

## ----gif, eval = FALSE--------------------------------------------------------
# render_gif(
#   f,
#   tour_path = guided_tour(holes()),
#   display   = display_xy(col = flea$species),
#   gif_file  = "guided_flea.gif",
#   frames    = 60
# )

