[R-sig-phylo] plotting character states on a circular cladogram

Emmanuel Paradis Emmanuel.Paradis at ird.fr
Fri Feb 3 08:28:53 CET 2012

Rafael Rubio de Casas wrote on 02/02/2012 22:02:
>   Hi,
> Thanks, Emmanuel. I did try to play around with tip.labels (by the by, I
> did not know it called points, although I guess it makes a lot of sense).
> The problem I run into is that, for some reason, label.offset does not
> seem to work with the graphical labels. For instance, I would expect two
> concentric circles of colored dots with:

It is indeed possible to do what you want (the code is in plot.phylo), 
but since you are working on a textbook example, my humble suggestion is 
to use a linear tree for this; it'll be also much easier to plot 
information on several traits. You'll get the same information with a 
"fan" tree but more difficult to decrypt by the human eye -- though 
others might have different opinions on this.

> plot(phy, type="fan", label.offset=5, plot=FALSE)
> tiplabels(pch=21, cex=1.5, bg=label[phy$tip.label])
> par(new=TRUE)
> plot(phy, type="fan", label.offset=2, plot=FALSE)
> tiplabels(pch=21, cex=1.5, bg=label[phy$tip.label])
> However only one is produced, and those dots are placed right on the
> tips. You can see that if you then follow with
> par(new=TRUE)
> plot(phy, type="fan", label.offset=2)
> I guess this is mostly irrelevant, But I am working on a figure for a
> book and I would like it to be a "textbook example"
> Also, when node states are drawn with nodelabels(), if if the terminal
> branches are very short, the plot of the nodes get confused with those
> of the tips
> For instance, if you try:
> ace.ER=ace(trait,phy,type="discrete")
> nodelabels(pie=ace.ER$lik.anc, piecol=c("dodgerblue","firebrick"),
> cex=0.5,lwd=0.5)
> You can see that the last node plots are at the same level of the tip
> plots. If tips were denser (i.e., if the tree had more terminals) that
> would make the plot virtually unreadable.

You might prefer to plot your tree with:

plot(phy, "c", FALSE)

You might want to try 'thermo' instead of 'pie'.



> Cheers,
> Rafa
> On 2/2/2012 7:03 AM, Emmanuel Paradis wrote:
>> Hi Rafael,
>> Rafael Rubio de Casas wrote on 02/02/2012 06:24:
>>> Hi Nicolai,
>>> Thanks for your message. I guess I wasn't completely clear in my
>>> previous message.
>>> tiplabels() does do a similar thing to what I want. In fact, it is what
>>> I ahve been using. The problem is that I think that with tiplabels you
>>> cannot place the colored dots at a particular position relative to the
>>> tips on a circular cladogram.
>> You are right.
>>> I thought that points() would be easier to adapt for that, but maybe
>>> not.
>> tiplabels() actually calls points() so you have to tell the function
>> how to offset the coordinates which is not obvious because they are
>> circular, -- though plot.phylo() does it when label.offset is used.
>> I guess what you want is to prevent the labels to hide the terminal
>> edges. Here's a suggestion for this:
>> plot(phy, type="fan", label.offset=2, plot=FALSE)
>> tiplabels(pch=21, cex=1.5, bg=label[phy$tip.label])
>> par(new=TRUE)
>> plot(phy, type="fan", label.offset=2)
>> The idea is to first draw the tip labels, and then the tree, so that
>> the terminal edges are not hidden by the labels. The first line sets
>> the drawing region but nothing is plotted so the labels can be drawn.
>> The trick is to call par(new=TRUE) so that plot() does not refresh the
>> graph.
>> HTH
>> Emmanuel
>>> Thanks for your help, anyways.
>>> Cheers,
>>> Rafa
>>> On 2/1/2012 5:25 PM, Nicolai Cryer wrote:
>>>> Hey Rafael,
>>>> (By the way, thanks for the easily reproducible code).
>>>> I think you're looking for the tiplabels() function, so instead of
>>>> using points, try:
>>>> tiplabels(pch=21,cex=1.5, bg=label[phy$tip.label])
>>>> This should amount to the same kind of color coding, but the layout
>>>> doesn't break when plotting a radial tree.
>>>> Hope that helps,
>>>> Best,
>>>> Nicolai
>>> On 2/1/2012 2:40 PM, Rafael Rubio de Casas wrote:
>>>> Dear R-Sig-Phylo users,
>>>> I have what I believe should be an easy problem:
>>>> I want to plot character states on the tips of a fan cladogram produced
>>>> by ape.
>>>> What I am looking for, I believe, is something similar to what you can
>>>> do with "points" on a rectangular phylogram. That is, assign points to
>>>> tips colored according to their trait value.
>>>> For instance, the following code generates what I want for a
>>>> rectangular
>>>> phylogram:
>>>> library(ape); library(geiger)
>>>> phy=rcoal(25, tip.label=c(letters[1:25]))
>>>> phy=rescaleTree(phy,25)
>>>> trait=as.vector(sample(0:1,25,replace=T))
>>>> names(trait)=phy$tip.label
>>>> label=character(length(phy$tip.label))
>>>> names(label)=names(trait)
>>>> label[trait==0]="dodgerblue"
>>>> label[trait==1]="firebrick"
>>>> plot(phy, show.tip.label=T, label.offset=1.5,no.margin=TRUE)
>>>> points(rep(26, length(phy$tip.label)), 1:length(phy$tip.label), pch=21,
>>>> cex=1.5, bg=label[phy$tip.label])
>>>> My problem is that I don't know how to get the same sort of mapping of
>>>> trait states at the tips when using
>>>> plot(phy, type="fan")
>>>> Thanks in advance,
>>>> Rafa
> --
> National Evolutionary Synthesis Center
> *NESCent <http://www.nescent.org/>*
> 2024 W. Main Street, Suite A200
> Durham, NC27705
> rafa at nescent.org <mailto:rfr6 at duke.edu>
> 919.668.9107

Emmanuel Paradis
IRD, Jakarta, Indonesia

More information about the R-sig-phylo mailing list