trianglePlotter: Plot a phylogeny with triangles representing clades

View source: R/trianglePlotter.R

trianglePlotterR Documentation

Plot a phylogeny with triangles representing clades

Description

Use the optimal collapses to create a tree where triangles represent clades.

Usage

trianglePlotter(
  orig.tree,
  poly.tree,
  states.df,
  dropped.result,
  oc.result,
  branches,
  is.result,
  translation.table,
  label.offset,
  text.cex,
  pt.cex,
  seg.lwd
)

Arguments

orig.tree

A phylogeny in ape format. This should be the original tree.

poly.tree

A phylogeny in ape format. This should be the polytomy tree, i.e. the result of a call to polytomyBind.

states.df

Data frame in the specified shiftPlot format. Should contain one column named "state", and number for every node in the phylogeny, with the tips above the internal nodes, and no row names. See details and examples.

dropped.result

The result of a call to dropManyTips.

oc.result

The result of a call to optimalCollapse. Data frame with four columns: node, state, collapse (0/1), and clade. Node provides values indicating which nodes you will collapse (all nodes tipwards from the indicated node will be collapsed). Collapse indicates whether to actually collapse that node or not (allowing a user to manually override the results from optimalCollapse). Clade provides a character string which will be used to rename the collapsed clade. Initially, this is given a generic name based on the node being collapsed, but these can be replaced with a name of the user's choosing.

branches

Result of a call to firstBranches.

is.result

Result of a call to identifyShifts.

translation.table

A data frame with the following two columns: "state" and "color", the name of the color to use in the plot to indicate that that trait state. Color can be specified in a variety of ways–word, hexadecimal, probably rgb but untested.

label.offset

How far away from the tips the clade name should be positioned.

text.cex

The size of the clade labels.

pt.cex

The size of the dots used to indicate shifts. Set to 0 to suppress points.

seg.lwd

Width of the edges in the plotted phylogeny.

Details

Ambitions of making this work for radial trees too.

Author(s)

Eliot Miller and Bruce Martin

Examples

#start with a corHMM output and build up a states.df
#load data. these are the results of following the corHMM precursor model vignette
data(Precur_res.corHMM)
data(phy)
nodeStates <- data.frame(state=Precur_res.corHMM$states[,3]+Precur_res.corHMM$states[,4])
tipStates <- data.frame(state=Precur_res.corHMM$tip.states[,3]+Precur_res.corHMM$tip.states[,4])

#note that tip states comes first here!
states <- rbind(tipStates, nodeStates)

#binarize this. choosing to call 0.5 chance of having trait present
states$state[states$state >= 0.5] <- 1
states$state[states$state < 0.5] <- 0

#flip node 103 and all nodes towards tips from there to trait = absent
induced <- states
induced[geiger:::.get.descendants.of.node(103, phy),] <- 0
induced[103,] <- 0

#get rid of row names
row.names(induced) <- NULL

#run the function and don't flip those tips
ocResult <- optimalCollapse(orig.tree=phy, states.df=induced, flip.tips=FALSE)

#run the dropManyTips fxn
dropped <- dropManyTips(orig.tree=phy, oc.result=ocResult)

#run the polytomyBind function
polyTree <- polytomyBind(dropped.result=dropped, oc.result=ocResult)

#run the firstBranches fxn
branches <- firstBranches(orig.tree=phy, dropped.result=dropped, oc.result=ocResult)

#run the function and don't flip those tips
is.result <- identifyShifts(orig.tree=phy, states.df=induced, flip.tips=FALSE)

#create a color, state, and state name translation table
translationTable <- data.frame(state=c(0,1), color=c("black","red"))

#make the triangle plot
trianglePlotter(orig.tree=phy, poly.tree=polyTree, dropped.result=dropped,
oc.result=ocResult, branches=branches, is.result=is.result,
label.offset=0.3, text.cex=0.09, translation.table=translationTable,
states.df=states, pt.cex=2, seg.lwd=0.1)

eliotmiller/shiftPlot documentation built on March 30, 2023, 4:26 a.m.