animate_evogram: animate_evogram View changes in the dendrogram over time. Has...

Description Usage Arguments Value Examples

View source: R/Animate_funcs.R

Description

animate_evogram

View changes in the dendrogram over time. Has most of the same options as plot_evogram, but does not have option to set link type

Usage

1
2
3
4
5
6
animate_evogram(size_df, clones, parents, fill_value = NULL,
  fill_range = NULL, time_pts = NULL, clone_cmap = NULL,
  threshold = 0.01, data_type = "size", fill_gaps_in_size = FALSE,
  test_links = TRUE, node_size = 5, scale_by_node_size = TRUE,
  orientation = "td", depth = "origin",
  rescale_after_thresholding = FALSE)

Arguments

size_df

Dataframe in a wide format, where each row corrsponds to a single clone, and the columns are the sizes of that clone at each timepoint

clones

Array containing the clone ids. The index of each clone must correspond to the same index of the row in size_df that contains the sizes of that clone over time

parents

Array containing the ids of the parent of each clone in the clones array.

fill_value

Array containing information that can be used to color each clone. If NULL (the default), each clone is assigned a color. If values are a clone attribute, e.g. fitness, then the colors are assigned according to those values. The user can also provide custom colors in 3 ways: 1) hexcode; 2) rgb values as a string, with each value being a the intensity of the color channel, each separated by commas, e.g. "255, 10, 128"; 3) Any of the named in colors in R, which can be found with colors

fill_range

Array containing the minimum and maximum values to set the range of colors. If NULL (the default), the range is determined directly from fill_value.

time_pts

Array containing the name of the timepoints. If NULL, then the name of timepoints will be a sequence from 1 to the number of columns in size_df.

clone_cmap

Colormap to use for the clones. For a list of available colormaps, see https://github.com/bhaskarvk/colormap.

threshold

The minimum frequency of clones to be plotted. Clones with with a frequency below this value will not be plotted

data_type

String defining what kind of information is in size_df. If "size", then the values in size_df are the population sizes. If "mutation", the values are the frequencies, between 0 and 1, of each mutation in the population over time

fill_gaps_in_size

Boolean defining whether or not missing sizes should be filled in

test_links

Make sure clone does not have the same id as it's parent. If true, it can cause infinite recursion.

node_size

Determines the size of nodes if scale_by_node_size is FALSE

scale_by_node_size

Boolean defining if the size of each node should be proportional to its frequency. If FALSE, then all nodes have the same size, determined by node_size

orientation

Defines orientation of the tree: "td" draws it top-down, "lr" draws it left-right

depth

Determines the y-position of the nodes: "level" places the nodes based on how deeply they are nested in the tree, "origin" makes the y-position the same as the clone's origin time, "bottom" positions nodes so that all leaves have the same position, furthest from the root

rescale_after_thresholding

Boolean determining if frequencies should be rescaled after thresholding, so that frequencies are based on what was above the threshold.

Value

List infromation need to craete the animation: "dendro_pos_df" contains all of the positions of the nodes and edges at each timestep, while "animation_plot" that can be used with gganimate to create the animation. For details on how to customize and save the animation, see gganimate

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
data("example.easy.wide.with.attributes")
### Split dataframe into clone info and size info using fact timepoint column names can be converted to numeric values
time_col_idx <- suppressWarnings(which(! is.na(as.numeric(colnames(example.easy.wide.with.attributes)))))
attribute_col_idx <- suppressWarnings(which(is.na(as.numeric(colnames(example.easy.wide.with.attributes)))))
size_df <- example.easy.wide.with.attributes[, time_col_idx]
parents <- example.easy.wide.with.attributes$parent
clones <- example.easy.wide.with.attributes$clone
fitness <- example.easy.wide.with.attributes$fitness
dendro_movie_info <- animate_evogram(size_df, clones = clones, parents = parents, fill_value = fitness)
dendro_movie_plot <- dendro_movie_info$animation_plot

### Add gganimate object to dendro_movie_plot to finish animation

library(gganimate)
movie_p <- dendro_movie_plot +
  transition_time(time) +
  ease_aes() +
  exit_shrink() +
  ggtitle('Time {frame_time}')

print(movie_p)

MathOnco/EvoFreq documentation built on Jan. 26, 2022, 7:31 p.m.