contMap: Map continuous trait evolution on the tree

View source: R/contMap.R

contMapR Documentation

Map continuous trait evolution on the tree


Projects the observed and reconstructed values of a continuous trait onto the edges of a tree using a color gradient.


contMap(tree, x, res=100, fsize=NULL, ftype=NULL, lwd=4, legend=NULL,
   lims=NULL, outline=TRUE, sig=3, type="phylogram", direction="rightwards", 
   plot=TRUE, ...)
## S3 method for class 'contMap'
plot(x, ...)
errorbar.contMap(obj, ...)



object of class "phylo".


a numerical vector of phenotypic trait values for species. names(x) should contain the species names and match tree$tip.label. Or, for plot.contMap, an object of class "contMap".


resolution for gradient plotting. Larger numbers (to a point) indicate a finer (smoother) gradient.


relative font size - can be a vector of length 2 in which the first element gives the font size for the tip labels & the second element giving the font size for the legend.


font type - see options in plotSimmap. As with fsize, this can be a vector with the second element giving font type for the legend.


line width for branches. Can be a single integer number or a vector. In the latter case, the second number will be taken to be the desired legend width.


if FALSE no legend is plotted; if a numeric value, it gives the length of the legend in units of branch length. Default is 0.5 times the total tree length.


range for the color map. By default, this will be c(min(x),max(x)), and should always include this range.


logical value indicating whether or not to outline the branches of the tree in black.


the number of decimal places to show on the legend limits.


type of plot desired. Options are "phylogram" for a rightward square phylogram; and "fan" for a circular phylogram.


plotting direction for type="phylogram".


logical value indicating whether or not to plot the tree. If plot=FALSE then an object of class "contMap" will be returned without plotting.


object of class "contMap".


optional arguments for plot.contMap which include all the arguments of contMap except for tree, x, res, and lims. Also method, "fastAnc", "anc.ML", or "user" (for user-supplied states) specifying which function to use for ancestral state estimation; hold specifies whether or not to hold output to graphical device before plotting (defaults to hold=TRUE); and anc.states a vector containing some or multiple ancestral user-supplied ancestral states at nodes. Some other plotting arguments, such as xlim and ylim, may also work. Optional arguments for errorbar.contMap include x, a vector containing the original trait values mapped onto the tree (otherwise these will be obtained from obj),, a logical argument (defaulting to TRUE) that determines whether or not the length of the error bars will be scaled by the CI width, and lwd, which determines the line width of the plotted error bars.


Function plots a tree with a mapped continuous character.

The mapping is accomplished by estimating states at internal nodes using ML with fastAnc, and then interpolating the states along each edge using equation [2] of Felsenstein (1985). This makes these interpolated values equal to the maximum likelihood estimates under a Brownian evolutionary process.

The default color palette is not recommended as it is not colorblind friendly and does not render well into gray scale; however, this can be updated using the helper function setMap.

errorbar.contMap adds error bars to an existing plot.


Plots a tree. An object of class "contMap" is returned invisibly.

errorbar.contMap adds colorful error bars to a plotted tree.


Liam Revell


Felsenstein, J. 1985. Phylogenies and the comparative method. American Naturalist, 125, 1-15.

Revell, L. J. (2012) phytools: An R package for phylogenetic comparative biology (and other things). Methods Ecol. Evol., 3, 217-223.

Revell, L. J. 2013. Two new graphical methods for mapping trait evolution on phylogenies. Methods in Ecology and Evolution, 4, 754-759.

See Also

anc.ML, densityMap, fastAnc, plotSimmap


## load data from Garland et al. (1992)
## extract character of interest
## create "contMap" object
## change color scheme
    leg.txt="log(body mass)")
par(mar=c(5.1,4.1,4.1,2.1)) ## reset margins to default

phytools documentation built on Nov. 10, 2023, 1:08 a.m.