array2df: Turns a tour path array into a long data frame.

View source: R/0_util.r

array2dfR Documentation

Turns a tour path array into a long data frame.

Description

Internal function, many end users will not need this. Takes the result of manual_tour() or tourr::save_history(). Restructures the array of interpolated bases into a long data frame for use in ggplots.

Usage

array2df(
  basis_array,
  data = NULL,
  basis_label = NULL,
  data_label = rownames(data),
  do_center_frame = TRUE
)

Arguments

basis_array

A full (p, d, n_frames) interpolated basis array of a tour, the output of manual_tour or save_history(*_tour()).

data

Optional, (n, p) dataset to project, consisting of numeric variables.

basis_label

Labels for basis display, a character vector with length equal to the number of variables. Defaults to NULL; 3 character abbreviation from colnames of data or rownames of basis.

data_label

Labels for plotly tooltip display. Defaults to the rownames of data. If null, initializes to 1:nrow(data).

do_center_frame

Whether or not to center the mean within each animation frame. Defaults to TRUE.

Examples

## !!This function is not meant for external use!!
dat  <- scale_sd(wine[, 2:6])
clas <- wine$Type
bas  <- basis_pca(dat)
mv   <- manip_var_of(bas)

## Radial tour array to long df, as used in play_manual_tour()
mt_array <- manual_tour(basis = bas, manip_var = mv)
ls_df_frames <- array2df(basis_array = mt_array, data = dat,
                         basis_label = paste0("MyLabs", 1:nrow(bas)))
str(ls_df_frames)

## tourr::save_history tour array to long df, as used in play_tour_path()
gt_array <- tourr::save_history(data = dat, max_bases = 10)
ls_df_frames2 <- array2df(basis_array = gt_array, data = dat)
str(ls_df_frames2)

spinifex documentation built on March 31, 2022, 9:06 a.m.