color.terminal.branches - Color only the terminal branches of a phylogeny by the corresponding trait value

The code for this function can be found here. The function has the potential to take many arguments:

To demonstrate some functionality, we first need to simulate some phylogenetic and trait data


phy <-"example_phylogeny.nex")

# Create some random dstate data
states <- sample(seq(1,40,1), 17)
names(states) <- phy$tip.label

##      Dryocopus_lineatus      Dryocopus_pileatus       Campethera_nivosa 
##                       5                      37                      16 
##   Geocolaptes_olivaceus             Picus_canus Blythipicus_rubiginosus 
##                       1                       4                       8
# Load the function code

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 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 '' argument
color.terminal.branches(phy, small.range.states, breaks=4, cols=c("black","red"), edge.width=2,show.tip.label=TRUE, = states)