Two new graphical methods for mapping trait evolution on phylogenies


Correspondence author. E-mail:


  1. Modern phylogenetic comparative biology uses data from the relationships between species (phylogeny) combined with comparative information for phenotypic traits to draw model-based statistical inferences about the evolutionary past. Recent years have seen phylogeny methods for evolutionary inference become central in the study of organic evolution.
  2. Here, I present two different graphical methods for visualizing phenotypic evolution on the tree. Method 1 is a new approach for plotting the posterior density of stochastically mapped character histories for a binary (two-state) phenotypic trait on a phylogeny. Method 2 is a closely related technique that uses ancestral character estimation to visualize historical character states for a continuous trait along the branches of a tree.
  3. One shortcoming of Method 2 is that by mapping the point estimates of ancestral states along the branches of the tree, we have effectively ignored the uncertainty associated with ancestral character estimation of continuous traits. To alleviate this issue, I propose a new method for visualizing ancestral state uncertainty using a type of projection of the tree into morphospace called a ‘traitgram.’
  4. All of these approaches should prove useful in summarizing complex comparative inferences about ancestral character reconstruction. They are implemented in the freely available and open-source R phylogenetics package ‘phytools.’


Evolutionary biology is a historical discipline: large evolutionary changes take place over long time-scales and thus cannot be studied directly. One of the most important tools in the arsenal of scientists studying the evolutionary past is phylogenetic comparative biology (Felsenstein 1985, 2004; Harvey & Pagel 1991). Phylogenetic comparative biologists combine the phylogeny (that is, one or multiple estimates of the relationships and divergence times between taxa) with data for the phenotypic traits of species to make inferences about evolutionary processes in deep time (Harmon et al. 2010; Mahler et al. 2010; O'Meara 2006). In recent years, phylogenetic comparative approaches have become central in evolutionary biology (Miles & Dunham 1993; Freckleton, Harvey & Pagel 2002; Losos 2011).

One component of studying the evolutionary past is reconstructing the past phenotypes of extinct ancestral species from the trait values of their extant descendants (Huey & Bennett 1987; Maddison 1991; Schluter et al. 1997; Pagel 1999). Modern approaches for ancestral character reconstruction treat the states at ancestral nodes as parameters or variables in a statistical model and use techniques such as maximum likelihood or Bayesian MCMC to fit the model of evolution and estimate ancestral character values. For example, using a method called stochastic character mapping, developed by Neilsen (2002; Huelsenbeck, Nielsen & Bollback 2003), we can sample possible histories of a discretely valued character from their Bayesian posterior probability distribution. A single such character history is meaningless; however, in aggregate, a large number of discrete stochastic character maps (say, 100 to 1000) can be used to estimate the history of a discretely valued character trait evolving on the tree. In addition, the variability among sampled histories provides a measure of the uncertainty we have about trait evolution in our clade of interest (e.g. Collar et al. 2009; Kelly, Near & Alonzo 2012).

A stochastic character mapping analysis will result in a large number of discrete character histories on a phylogeny. These data are difficult to visualize in a figure for publication. For instance, one might display the result of one or a small number of representative stochastic histories (e.g. Collar et al. 2009; Price et al. 2013); but this ignores the fact that the stochastic maps should be considered in aggregate. Alternatively, one might compute the marginal probability of the character being in each state at all internal nodes of the tree (e.g. Kelly, Near & Alonzo 2012); but this ignores the trait values for the character along internal edges, which represent an important component of stochastic maps. Both of these approaches have been taken in recent empirical studies.

In this note, I present a new approach for visualizing the posterior density of a binary character state on a phylogenetic tree from stochastic mapping. In addition, I present a closely related, visually similar technique for mapping the estimated state of a continuous character on the tree. I have illustrated the two methods with an empirical analysis of published data. R is a programming language and scientific computing environment with a large and growing community of users in phylogenetic biology (R Development Core Team 2013). Both of these methods are implemented in the freely available, multifunctional, open-source R phylogenetics package, ‘phytools’ (Revell 2012). phytools is available from the Comprehensive R Archive Network, CRAN.

Methods and results

In this note, I present two closely related approaches for visualizing trait evolution on a phylogeny. Method 1 is a technique for visualizing the posterior density of character histories obtained by aggregating the results from a set of stochastic character maps. Method 2 is a related approach to graph the reconstructed states for ancestral species in a continuous character along the edges and nodes of a phylogeny. I will describe each method and illustrate its use with an empirical example from published studies, in the sections below.

Visualizing the aggregate result of stochastic mapping – Method 1 involves aggregating the results of a large number of stochastic character maps. For example, Fig. 1 shows three of 1000 stochastic character maps for the binary character of piscivory (red) vs. non-piscivory (blue) in the phylogeny of sunfishes (Centrarchidae; Near, Bolnick & Wainwright 2005; Collar et al. 2009; Revell & Collar 2009).

Figure 1.

A sample of three stochastic character maps for the evolution of feeding mode in Centrarchidae. Phylogeny and data are from Near, Bolnick & Wainwright (2005) and Collar et al. (2009).

Stochastic character mapping is a technique whereby possible character histories are sampled in proportion to their probability. Each sample contains a specific, unique and subtly or markedly different character history – for instance, the first two trees of Fig. 1 imply that piscivory was the ancestral feeding mode in centrarchids; whereas the third stochastic map implies non-piscivory at the root node of the tree. Consequently, stochastic character maps are only meaningful when considered in aggregate.

Here, I propose a new approach for visualizing the aggregate result from stochastic character mapping of a binary trait. According to this procedure, we finely fraction the branches of the tree and then compute the posterior probability of the state being in either condition ‘0’ or condition ‘1’ for each fraction as the relative frequency across all stochastic maps. When a fraction is bisected by a state change, the two states both contribute to the cumulative probability – weighted by the relative branch length spent in each state. We can then plot these probabilities on the branches of the tree using a colour map to translate the probability to a plotted colour. The result (so long as a sufficient number of stochastic histories are generated) is that the probability density appears to change continuously along the branches of the tree. This method is implemented in the function densityMap of the R phylogenetics package, phytools (Revell 2012). I have applied the method to the full sample of 1000 stochastically mapped trees for feeding mode in Centrarchidae, of which just three stochastic maps are given in Fig. 1. The result is shown in Fig. 2. The horizontal bar at the bottom of the graph in Fig. 2 is at the same time both a legend and scale: the colour map translates the heat colours (blue through red) into the posterior probability of feeding mode being in the condition ‘piscivory’; and the total length of the bar also provides a scale for the branch lengths of the tree. Figure 2 suggests that the ancestral feeding mode should be considered highly uncertain for about the first 1/3 of the tree; but this was followed by multiple acquisitions of piscivory or non-piscivory or both. This visualization, particularly the uncertain condition of many ancestral branches in the tree, is more revealing that any single stochastic map considered in isolation. Stochastic character mapping can be conducted in R using the phytools function make.simmap (Revell 2012); or with the stand-alone Mac OS program SIMMAP (Bollback 2006). (For a description of stochastic mapping in phytools, please refer to the phytools documentation.) Stochastically mapped phylogenies simulated using SIMMAP v1.0 or v1.5 can easily be read into the R environment using the phytools function read.simmap (Revell 2012).

Figure 2.

The results from 1000 stochastic character maps (the three shown in Fig. 1, plus 997 others) displayed in aggregate. The colour of edges in the tree gives the posterior probability (computed as the relative frequency across stochastic maps) of each feeding mode through the history of the clade. Red indicates high posterior probability of piscivorous feeding mode. The length of the legend also gives a scale for the branch lengths of tree, in this case in units of substitution per site for five mitochondrial and four nuclear genes (Near, Bolnick & Wainwright 2005).

Visualizing ancestral estimates for continuous traits – Whereas Method 1 is designed to aggregate the results of many discrete character histories, Method 2 uses a visually similar approach to plot the estimated history of a continuously valued trait on the tree. Here, we first estimate the ancestral characters at internal nodes using, for instance, maximum likelihood (ML; Schluter et al. 1997). For simplicity, I assume Brownian motion as a model for trait evolution (Cavalli-Sforza & Edwards 1967; Felsenstein 1973, 1985); however, the method could be adapted to other evolutionary models such as the Ornstein–Uhlenbeck model (Hansen 1997; Butler & King 2004). Next, we finely fraction all edges (as in Method 1), and then compute the state estimates at the mid-point of each fraction via interpolation. Again, this creates the visual appearance of continuous colour change along the edges of the tree. I interpolated the internal states along branches using equation (3) of Felsenstein (1985). Here, the target ancestral value at some arbitrary point along an edge in the tree, math formula, is a function of the observed or ML estimated states at the subtending nodes or tips i and j (xi and xj), as well as the phylogenetic distances to nodes i and j (vi and vj):

display math

Figure 3 shows an example analysis of the evolution of body size (log-transformed snout-to-vent length, SVL) in 100 species of Greater Antillean Anolis lizards (Mahler et al. 2010). As in Fig. 2, the horizontal bar is both a legend and scale. The colour map represents observed and reconstructed values for SVL on the tree. Red colours correspond with relatively low values for SVL; whereas green through blue colours represent larger observed and reconstructed trait values. This visualization can be reproduced using the phytools function contMap.

Figure 3.

Ancestral character estimation of body size (log-transformed snout-to-vent length) along the branches and nodes of the tree for Greater Antillean Anolis lizards. The total tree length was arbitrarily rescaled to unit length in this analysis, following the original authors. Phylogeny and data are from Mahler et al. (2010).

One obvious shortcoming of this approach is that by plotting only the point estimate of phenotype at the nodes and along the branches of the tree, we are ignoring the considerable uncertainty that can be inherent in ancestral state estimation (Schluter et al. 1997; Losos 2011). Figure 4 shows a different kind of visualization – a type of projection of the phylogenetic tree into trait space, called a ‘traitgram’ by Ackerly (2009), here performed using a simulated phylogeny and dataset. In a traitgram, the vertical position of nodes and edges give known or estimated phenotypic trait values, while the horizontal position gives time or patristic distance from the root. Traitgrams have been used in a number of prior publications (e.g. Ackerly 2009; Evans et al. 2009). The innovative aspect of Fig. 4 is that in addition to showing the estimated ancestral values for the phenotypic trait, it also shows uncertainty about ancestral states along branches and at nodes. To do this, I computed the confidence intervals at internal nodes and then linearly interpolated along branches. Increasing quantiles away from the point estimate are shown via increased transparency of the plotted density. This visualization is implemented as a method of the phytools function fancyTree, using type =‘phenogram95’. fancyTree calls the phytools function phenogram internally. One nice aspect of phenogram over other implementations of traitgram plotting (e.g. Kembel et al. 2010) is that phenogram can accept user-supplied penalties (or ‘costs’) for label overlap and then uses numerical methods to optimize the spacing of tip labels on the trait axis. This can be very helpful because multiple species often have similar trait values (Fig. 4), which can make their tip labels difficult to read if plotted conventionally (i.e. directly adjacent to the tips).

Figure 4.

A projection of the phylogeny into a space defined by phenotype (on y) and time since the root. The vertical position of nodes and branches are computed via ancestral character estimation using likelihood (e.g. Schluter et al. 1997). Uncertainty is shown via increasing transparency of the plotted blue lines around the point estimates with the entire range showing the 95% confidence interval.


Herein, I present two new methods, implemented in computer software, to visualize trait evolution on a phylogeny. The first of these, Method 1, is an approach to aggregate the results from a procedure called stochastic character mapping. In stochastic character mapping, we sample character histories (such as those shown in Fig. 1) in proportion to their probability conditioned on a model (Neilsen 2002; Huelsenbeck, Nielsen & Bollback 2003). These character-mapped phylogenies can then be used in subsequent analyses, such as in model-fitting for comparative biology (O'Meara et al. 2006) or in computing the mean and distribution of trait changes on the tree (e.g. Kelly, Near & Alonzo 2012). Thus, for instance, one might fit a model of evolution to each tree in the set of mappings, and then compute the mean result across trees (Collar et al. 2010; Revell 2013). One difficulty with these mappings is that they are relatively meaningless in isolation and should be considered in aggregate. There is no difficulty for analytic techniques such as those described previously, but presents a challenge for visualization. The typical response in prior studies has been to plot one or a small number of stochastic maps; or to compute and plot the posterior probability at nodes, but ignore state changes that occur along the branches of the tree (e.g. Collar et al. 2009, 2010; Kelly, Near & Alonzo 2012; Price et al. 2013). In this article, I illustrate a new method for visualizing the aggregate result of stochastic mapping of a binary character in which we map posterior density on the tree using a continuous colour gradient.

An inherent shortcoming of this method is that it is only sensible for a binary trait – in which case the plotted colour is a proxy for the probability of being in an identified condition (such as the feeding mode ‘piscivory’). For multistate character traits, options for visualizations of this type are less obvious; however, it would be no trouble to plot the posterior probability of being in any specific discrete character state. For instance, given nucleotide data, we could use this method to plot the ‘probability of T’ vs. ‘the probability of not-T’ on the branches of the tree, even though there are actually four distinct nucleotide states. One option for plotting the probability of three states is to use saturation in three dimensions on an RGB (‘red-green-blue’) colour model. This may be incorporated into a future version of ‘phytools,’ but extension to four or more trait values is not obvious.

Method 2 is a closely related visualization technique, but for continuous trait evolution. Here, I computed the ML estimates at internal nodes, and then I interpolated ancestral condition along the branches of the tree using equation (3) of Felsenstein (1985). Visualizing quantitative trait evolution for a single character can alternatively be performed using the ‘traitgram’ approach in which the vertical dimension of a phylogeny is projected onto a phenotypic trait axis (e.g. Fig. 4). The horizontal dimension is time, and edges connect species trait values to the trait values of their hypothesized ancestors (Ackerly 2009; Kembel et al. 2010; Revell 2012). The trouble with this method is that the phylogenetic relationships of species in a traitgram can be difficult to discern, particularly when species in different parts of the phylogeny have similar phenotypes. The new visualization technique presented here alleviates this difficulty by simultaneously portraying trait evolution and representing the phylogeny in conventional way.

As noted earlier, a significant shortcoming of this approach is that (by mapping the point estimate of ancestral traits) we are ignoring the considerable uncertainty that invariably accompanies said estimates. It is not clear how to incorporate measures of uncertainty without totally obfuscating the clarity of visualizations such as that of Fig. 3. To address this concern, I propose a new method to graph uncertainty in traitgrams. This is illustrated in Fig. 4 with simulated data. Unfortunately, this visualization is still limited by the difficulty traitgrams pose in discerning phylogenetic relationships, as described above.

All the plotting techniques described in this article are implemented in the open-source R phylogenetics package ‘phytools’ (Revell 2012). Phylogenetic comparative biology in R has exploded in recent years, with many new packages and functions (e.g. Harmon et al. 2008; Kembel et al. 2010; Boettiger, Coop & Ralph 2012; Fitzjohn 2012). Most, including phytools, rely extensively on the important core phylogenetics package, ‘ape’ (Paradis, Claude & Strimmer 2004; Paradis 2012).

Phylogenetic comparative biology has become central in the study of evolution over the past 25 years. Many methodological advances have been made, but these methods also pose new and interesting visualization challenges. Here, I describe several methods for visualizing ancestral states on the branches and nodes of a phylogeny. These approaches add considerably to our set of plotting techniques for ancestral character reconstruction on phylogenies.


Thanks to L. Mahler for his suggestion that I develop a continuous trait version of Method 1. Associate editor and reviewer comments significantly improved this version of the manuscript over previous ones and also served to inspire the development of traitgram plotting with uncertainty (as illustrated in Fig. 4).