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.
array2df(
basis_array,
data = NULL,
basis_label = NULL,
data_label = rownames(data),
do_center_frame = TRUE
)
A full (p, d, n_frames) interpolated basis array of a
tour, the output of manual_tour
or save_history(*_tour())
.
Optional, (n, p) dataset to project, consisting of numeric variables.
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.
Labels for plotly
tooltip display.
Defaults to the rownames of data. If null, initializes to 1:nrow(data).
Whether or not to center the mean within each animation frame. Defaults to TRUE.
## !!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)
#> List of 2
#> $ basis_frames:'data.frame': 5 obs. of 4 variables:
#> ..$ x : num [1:5] 0.0934 0.4287 0.6507 0.5784 0.2223
#> ..$ y : num [1:5] 0.658 -0.134 0.184 -0.434 0.572
#> ..$ frame : num [1:5] 1 1 1 1 1
#> ..$ tooltip: chr [1:5] "MyLabs1" "MyLabs2" "MyLabs3" "MyLabs4" ...
#> ..- attr(*, "manip_var")= Named int 4
#> .. ..- attr(*, "names")= chr "Alcohol"
#> $ data_frames :'data.frame': 178 obs. of 4 variables:
#> ..$ x : num [1:178] 0.541 0.306 0.638 0.573 0.788 ...
#> ..$ y : num [1:178] 0.976 0.684 0.558 0.866 0.66 ...
#> ..$ frame : num [1:178] 1 1 1 1 1 1 1 1 1 1 ...
#> ..$ tooltip: int [1:178] 1 2 3 4 5 6 7 8 9 10 ...
## 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)
#> target_dist - cur_dist: 0
#> generation: dist = 1.477531
#> target_dist - cur_dist: 1.477531
#> generation: dist = 1.238456
#> target_dist - cur_dist: 0
#> generation: dist = 1.468007
#> target_dist - cur_dist: 0
#> generation: dist = 1.813149
#> target_dist - cur_dist: 0
#> generation: dist = 1.271025
#> target_dist - cur_dist: 0
#> generation: dist = 1.86552
#> target_dist - cur_dist: 0
#> generation: dist = 1.59537
#> target_dist - cur_dist: 0
#> generation: dist = 1.412325
#> target_dist - cur_dist: 0
#> generation: dist = 1.739049
#> target_dist - cur_dist: 0
#> generation: dist = 1.179378
#> target_dist - cur_dist: 0
#> generation: dist = 1.520137
ls_df_frames2 <- array2df(basis_array = gt_array, data = dat_std)
str(ls_df_frames2)
#> List of 2
#> $ basis_frames:'data.frame': 50 obs. of 4 variables:
#> ..$ x : num [1:50] 0.0191 0.8044 -0.2638 0.3386 -0.4103 ...
#> ..$ y : num [1:50] -0.744 -0.178 -0.247 -0.327 -0.496 ...
#> ..$ frame : num [1:50] 1 1 1 1 1 2 2 2 2 2 ...
#> ..$ tooltip: chr [1:50] "Alch" "Mlc" "Ash" "Alcl" ...
#> $ data_frames :'data.frame': 1780 obs. of 4 variables:
#> ..$ x : num [1:1780] 0.262 0.351 0.439 0.351 0.401 ...
#> ..$ y : num [1:1780] 0.219 0.548 0.382 0.237 0.239 ...
#> ..$ frame : num [1:1780] 1 1 1 1 1 1 1 1 1 1 ...
#> ..$ tooltip: int [1:1780] 1 2 3 4 5 6 7 8 9 10 ...