display_pca: Display tour path with principal component scores with...

View source: R/display-pca.r

display_pcaR Documentation

Display tour path with principal component scores with original axes

Description

Animate a 2D tour path on data that has been transformed into principal components, and also show the original variable axes.

Usage

display_pca(
  center = TRUE,
  axes = "center",
  half_range = NULL,
  col = "black",
  pch = 20,
  cex = 1,
  pc_coefs = NULL,
  edges = NULL,
  edges.col = "black",
  palette = "Zissou 1",
  ...
)

animate_pca(data, tour_path = grand_tour(), rescale = FALSE, ...)

Arguments

center

if TRUE, centers projected data to (0,0). This pins the center of data cloud and make it easier to focus on the changing shape rather than position.

axes

position of the axes: center, bottomleft or off

half_range

half range to use when calculating limits of projected. If not set, defaults to maximum distance from origin to each row of data.

col

color to use for points, can be a vector or hexcolors or a factor. Defaults to "black".

pch

shape of the point to be plotted. Defaults to 20.

cex

size of the point to be plotted. Defaults to 1.

pc_coefs

coefficients relating the original variables to principal components. This is required.

edges

A two column integer matrix giving indices of ends of lines.

edges.col

colour of edges to be plotted, Defaults to "black.

palette

name of color palette for point colour, used by hcl.colors, default "Zissou 1"

...

other arguments passed on to animate and display_slice

data

matrix, or data frame containing numeric columns

tour_path

tour path generator, defaults to 2d grand tour

rescale

Default FALSE. If TRUE, rescale all variables to range [0,1].

Examples

flea_std <- apply(flea[,1:6], 2, function(x) (x-mean(x))/sd(x))
flea_pca <- prcomp(flea_std, center = FALSE, )
flea_coefs <- flea_pca$rotation[, 1:3]
flea_scores <- flea_pca$x[, 1:3]
animate_pca(flea_scores, pc_coefs = flea_coefs)

tourr documentation built on May 29, 2024, 11:22 a.m.