Set up a data frame to make a plotly animation
make_animation_df.Rd
Set up a data frame to make a plotly animation
Arguments
- mpq_distances
The output from calling
get_mpq_distances
. Should be a list with elementsdistances
andr
, giving a list of distance objects and the corresponding values of r for the MPQr distance, respectively.- fn
A function to apply to each of the distance objects that creates a data frame with the variables in the animation. Its first argument should be a distance object. For example,
get_avg_distances_to_set
.- means_and_vars
Optional, defaults to NULL. If non-null, should be the output from the function
get_null_mean_and_variance
. It will add columnsnull_mean
,null_sd
,median
,lower
, andupper
, corresponding to those statistics of the null distribution for each value of r. Can be used to augment the plots with expected values under a null model.- ...
Extra arguments that are passed to fn.
- distance_list
A list of distance objects, for example, the
distance
element from the output ofget_mpq_distances
.
Value
A data frame that has one column called frame
(which
can be used by ggplot2 and plotly to make an animation).
Examples
data(small_otutab)
data(small_tree)
mpq_distances <- get_mpq_distances(small_otutab, small_tree)
# we give make_animation_df the mpq distances and a function we
# would like to apply to every distance matrix. The function
# requires an extra argument in addition to the distance matrix, so
# we pass that as `base_samples = c(1,2)` to specify that we want
# to call `get_avg_distances_to_set` on each distance matrix with
# the base samples set to be 1 and 2.
animation_df = make_animation_df(mpq_distances = mpq_distances, fn = get_avg_distances_to_set, base_samples = c(1,2))
# the resulting data frame has one column (frame) that corresponds
# to the different values of r and which can be used for animating
# the plot. The remaining columns are the columns created by `fn`
# (in this example, `get_avg_distances_to_set`.)
head(animation_df)
#> frame avg_dist site
#> ankarif...1 0 0.07071068 ankarif
#> banyong...2 0 0.07071068 banyong
#> beza1...3 0 0.07071068 beza1
#> beza2...4 0 1.65830965 beza2
#> brisefer...5 0 0.07071068 brisefer
#> korup...6 0 0.07071068 korup