Wednesday, August 4, 2021

Control subplot settings in plotTree.barplot

A phytools user asks:

“I have been using mostly the plotTree.barplot function of phytools but one thing I find difficult is how to manipulate the arguments that modify the appearance of the tree graph. I cannot find documentation that is clearly described in one place on how to manipulate for example the legend size, location or the distances among the bars. Whatever I have found is through existing examples on the internet or your blog. Is there somewhere documentation on available arguments for customizing the appearance of graphs (e.g., legend size, position, bar thickness etc)?”

plotTree.barplot has quite a lot of flexibility to control the options for both the plotted tree & the barplot, although it is not fully flexible.

Normally we do this using the arguments args.plotTree, args.barplot, and args.axis (the lattermost to control the appearance of the x-axis of our barplot panel).

Here's a quick demo. First, let's load phytools.


Now we can proceed to get some data & a tree. This tree & data come from Garland et al. (1992).

## Phylogenetic tree with 49 tips and 48 internal nodes.
## Tip labels:
##   U._maritimus, U._arctos, U._americanus, N._narica, P._lotor, M._mephitis, ...
## Rooted; includes branch lengths.
##               bodyMass homeRange
## U._maritimus     265.0    115.60
## U._arctos        251.3     82.80
## U._americanus     93.4     56.80
## N._narica          4.4      1.05
## P._lotor           7.0      1.14
## M._mephitis        2.5      2.50

Now I'm going to pull out my body size column as a vector with names.


OK, next let's use plotTree.barplot with the default settings.


plot of chunk unnamed-chunk-4

Now, I'm going to go ahead and modify some of the setting of plotTree as follows:


plot of chunk unnamed-chunk-5

Finally, let's also modify the barplot and axis arguments using args.barplot and args.axis respectively. Here, I'm also going to show my axis on the log-scale and update the labels to be nicer.

title(xlab="body mass")

plot of chunk unnamed-chunk-6

Not bad, right?


  1. Hi Liam, great blog. Is there any way to make a figure using two continous traits: dotTree (eg body size) and plottree.barplot (eg range size) together.

    All the best,


Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.