plt_recpd: Plot feature RecPD ancestral lineage reconstruction onto a...

View source: R/tree_plots.R

plt_recpdR Documentation

Plot feature RecPD ancestral lineage reconstruction onto a species phylogenetic tree.

Description

By default trees are plotted in 'willow tree' format, where the evolutionary distance between nodes/tips is mapped as branch width, instead of length.

Usage

plt_recpd(
  res,
  feat,
  map = c("anc_new", "anc_old"),
  tree.format = c("willow", "phylo"),
  direction = c("v", "h")
)

Arguments

res

A results data.frame generated by recpd_calc().

feat

A user-provided array of at least length 2, containing named features, or indices, corresponding to the feature column/rows of the recpd_calc() results data.frame.

map

Use finalized RecPD ancestral lineages ('anc_new') or preliminary state mappings ('anc_old').

tree.format

Plot tree as phylogram ('phylo') or in willow-tree ('willow') format.

direction

Plotting direction of the tree: either vertical ('v') or horizontal ('h').

Value

A ggtree object.

Author(s)

Cedoljub Bundalovic-Torma

Examples

library(ape)
library(dplyr)
library(ggplot2)

##Test case for a randomly generated tree (10 tips) and 10 randomly generated
###feature presence/absence (1, 0) data.frame.

#Generate a random phylogenetic tree:
n_tip <- 10
tree <- rtree(n_tip)

#Generate 10 randomly distributed features (rows = features, columns =
#phylogenetic tree tips):
tab <- replicate(10,
                 sapply(10, function(x) sample(c(0,1), x, replace=TRUE)),
                 simplify='matrix') %>%
 t() %>%
  data.frame(check.names=FALSE) %>%
  rename_with(function(x) tree$tip.label[as.numeric(x)])


#Perform ancestral lineage reconstruction with recpd_calc():
#res <- recpd_calc(tree, tab, calc=TRUE)

#Plot the tree:
#plt_recpd(res, 1) +
#   #Can also add ggplot2 elements, like a title:
#   labs(title = res %>%
#          filter(feature == 1) %>%
#         paste(colnames(.), '=', ., collapse = '\n'))


cedatorma/recpd documentation built on April 25, 2022, 10:14 p.m.