plot_phen: Plot the states of a phenotype or genotype along a...

View source: R/plot.phen.R

plot_phenR Documentation

Plot the states of a phenotype or genotype along a phylogenetic tree.

Description

This function is designed to visualise the reconstructed ancestral states of a variable along a phylogenetic tree. It uses colour to represent the states of terminal and internal nodes (if available), indicating changes between states by grey branches (except in the case of truly continuous variables).

Usage

plot_phen(
  tree,
  phen.nodes,
  snp.nodes = NULL,
  plot = TRUE,
  RTL = FALSE,
  LTR.snp = FALSE,
  main.title = NULL,
  align.tip.label = FALSE,
  show.axis = TRUE,
  ...
)

Arguments

tree

A phylo object.

phen.nodes

A vector containing the phenotypic state of either (i) only terminal nodes in tree or (ii) all nodes, terminal and internal in tree.

snp.nodes

An optional vector containing the states of a second variable (e.g., a genotypic variable) for either the terminal nodes or all nodes in the tree.

plot

A logical specifying whether to display a plot of the inputted phylogenetic tree with edges coloured to show the simulated phenotypic substitution process.

RTL

A logical variable indicating whether to plot the first or only tree from right to left (TRUE), or left to right (FALSE, the default).

LTR.snp

A logical variable indicating whether to plot the optional second tree from left to right (TRUE), or right to left (FALSE, the default).

main.title

Either NULL or a character vector specifying a main title for the plot.

align.tip.label

A logical indicating whether to align tip labels with each other (TRUE) or to place tip labels at terminal nodes (FALSE, the default).

show.axis

A logical indicating whether to add an axis showing the scale of branch lengths at the foot of the plot with axisPhylo (TRUE, the default) or not (FALSE).

Details

Ancestral states must be inferred in advance, for example, using function asr. States are then shown in the colour of terminal node labels and the colour of the edges of the tree. If only terminal states are available, these can be plotted along the tips of the tree. If desired, a second variable, for example, a particular SNP or genetic locus, can be shown along a second phylogeny. In this case, the second variable will be shown on a toplogically identical tree, which will be plotted from right to left, mirroring the first tree along the vertical axis of the plotting window. The RTL and LTR.snp arguments can be used to change the orientation/direction of the first and/or second tree.

Author(s)

Caitlin Collins caitiecollins@gmail.com

Examples


## Example 1 ##
## Not run: 
## load phylogenetic and phenotypic data:
data(tree)
data(phen)

## reconstruct phenotypic ancestral states:
phen.rec <- asr(var=phen, tree=tree, type="parsimony", method="discrete")

## plot phenotype along tree:
plot_phen(tree, phen.nodes=phen.rec)

## End(Not run)


## Example 2 ##
## Not run: 
## load phylogenetic and phenotypic data:
data(tree)
data(phen)

## load genotypic data:
data(snps)

## reconstruct phenotypic ancestral states:
phen.rec <- asr(var=phen, tree=tree, type="parsimony", method="discrete")

## reconstruct genotypic ancestral states:
snps.rec <- asr(var=snps, tree=tree, type="parsimony", method="discrete")

## plot both the phenotype and a genotype along tree:
plot_phen(tree, phen.nodes=phen.rec, snp.nodes=snps.rec[,1])

## End(Not run)


caitiecollins/treeWAS documentation built on March 9, 2024, 3:15 p.m.