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

## ----basic, eval = FALSE------------------------------------------------------
# animate_xy(flea[,1:6],
#   obs_labels = as.character(1:nrow(flea)),
#   axes = "off"
# )

## ----subset, eval = FALSE-----------------------------------------------------
# # Find the five points furthest from the multivariate centre
# d2    <- mahalanobis(flea[,1:6], colMeans(flea[,1:6]), cov(flea[,1:6]))
# top5  <- order(d2, decreasing = TRUE)[1:5]
# 
# # Build a label vector: empty for most points, row number for the top 5
# lbls <- rep("", nrow(flea))
# lbls[top5] <- as.character(top5)
# 
# animate_xy(flea[,1:6], obs_labels = lbls, axes="bottomleft")

## ----colour, eval = FALSE-----------------------------------------------------
# # Colour by species; label only row 1 and row 22 (arbitrary examples)
# lbls <- rep("", nrow(flea))
# lbls[c(1, 22)] <- rownames(flea)[c(1, 22)]
# 
# animate_xy(flea[,1:6],
#   col       = flea$species,
#   obs_labels = lbls,
#   axes      = "bottomleft"
# )

## ----gif, eval = FALSE--------------------------------------------------------
# lbls <- rep("", nrow(f))
# lbls[c(1, 22)] <- rownames(flea)[c(1, 22)]
# 
# render_gif(
#   flea[,1:6],
#   tour_path = grand_tour(),
#   display   = display_xy(
#     col        = flea$species,
#     obs_labels = labs,
#     axes       = "bottomleft"
#   ),
#   gif_file = "labelled_tour.gif",
#   frames   = 60,
#   width    = 400,
#   height   = 400
# )

## ----cex, eval = FALSE--------------------------------------------------------
# animate_xy(flea[,1:6],
#   obs_labels = as.character(1:nrow(f)),
#   axes = "off",
#   cex  = 0.6
# )

