The code for this function can be found here. The function has the potential to take many arguments:
phy
- Object of classphylo
data
- Named numeric vector, where the names match the tip labels inphy
breaks
- Numeric vetor of length 1 determining how many times to partitiondata
cols
- Character vector specifying the colors to be used in creating the color palette. See colorRamp for more informationnon.terminal.col
- Character vector of length 1, the color for the non-terminal branches in the phylogenyedge.width
- Numeric vector of length 1. The thickness of the following ape’s plot.phylocol.bias
- Numeric vector of length 1. A higher value will produce more widely spaced colors at higher trait values, see colorRamp for more informationlegend.title
- Character vector specifying the title for the legendshow.tip.label
- Logical. Show the tip labels of the phylogeny?alt.col.data
- Can specify additional data to generate the range of colors used to visualize the data of interest
To demonstrate some functionality, we first need to simulate some phylogenetic and trait data
library(ape)
phy <- read.nexus("example_phylogeny.nex")
# Create some random dstate data
states <- sample(seq(1,40,1), 17)
names(states) <- phy$tip.label
head(states)
## Dryocopus_lineatus Dryocopus_pileatus Campethera_nivosa
## 9 17 7
## Geocolaptes_olivaceus Picus_canus Blythipicus_rubiginosus
## 6 12 13
# Load the function code
source("color.terminal.branches.R")
A starting point plot
color.terminal.branches(phy, states, breaks=4, cols=c("black","red"), edge.width=2, show.tip.label=TRUE)
Using three colors, partitioning the data finer
color.terminal.branches(phy, states, breaks=8, cols=c("black","green","red"), edge.width=2)
If you wanted to make the non-terminal branches less obvious
color.terminal.branches(phy, states, breaks=8, cols=c("black","green","red"), edge.width=2,non.terminal.col = "gray")
If we want to color the branches using different data to calculate the colors then pass the data to the alt.col.data
argument.
# Generate data which is a smaller subset of the original state data
small.range.states <- sample(seq(30,40,0.1), 17)
names(small.range.states) <- phy$tip.label
# The original state data will be passed to the 'alt.col.data' argument
color.terminal.branches(phy, small.range.states, breaks=4, cols=c("black","red"), edge.width=2,show.tip.label=TRUE, alt.col.data = states)