Learn R Programming

spinifex (version 0.3.2)

array2df: 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)
)

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).

Examples

Run this code
# NOT RUN {
## !!This function is not meant for external use!!
dat_std <- scale_sd(wine[, 2:6])
clas <- wine$Type
bas <- basis_pca(dat_std)
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_std)#,
                         #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_std, max_bases = 10)
ls_df_frames2 <- array2df(basis_array = gt_array, data = dat_std)
str(ls_df_frames2)
# }

Run the code above in your browser using DataLab