# 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:

• phy - Object of class phylo
• data - Named numeric vector, where the names match the tip labels in phy
• breaks - Numeric vetor of length 1 determining how many times to partition data
• cols - Character vector specifying the colors to be used in creating the color palette. See colorRamp for more information
• non.terminal.col - Character vector of length 1, the color for the non-terminal branches in the phylogeny
• edge.width - Numeric vector of length 1. The thickness of the following ape’s plot.phylo
• col.bias - Numeric vector of length 1. A higher value will produce more widely spaced colors at higher trait values, see colorRamp for more information
• legend.title - Character vector specifying the title for the legend
• show.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)

names(states) <- phy$tip.label head(states) ## Dryocopus_lineatus Dryocopus_pileatus Campethera_nivosa ## 5 37 16 ## Geocolaptes_olivaceus Picus_canus Blythipicus_rubiginosus ## 1 4 8 # 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
color.terminal.branches(phy, small.range.states, breaks=4, cols=c("black","red"), edge.width=2,show.tip.label=TRUE, alt.col.data = states)