Tuesday, September 19, 2017

Custom tip label spacing in phenogram

Today I received the email:

“I would like to construct a phenogram for a paper using the phytools (v. 0.6-20) function phenogram when spread.labels argument is TRUE and ylim is greater than default range estimated by the function. I would like to provide more space along y axis since I want to 1) incorporate additional figures to the traitgram and 2) to make more space for tips so they are not overlapped. I was able to extend ylim, but current function do not take advantage of more space provided by the arbitrary range of ylim. Therefore, tips are (still) overlapped making it harder to read. Please, can you tell me if there is a hack that will enable function to exploit the full extent of arbitrary set ylim?.”

In fact, this is kind of already possible using the argument spread.range. Unfortunately, even this has some limitations.

First, the default:

## Optimizing the positions of the tip labels...

plot of chunk unnamed-chunk-1

Now, using spread.range:

## Optimizing the positions of the tip labels...

plot of chunk unnamed-chunk-2

What has happened is that although the labels are spread out to utilize more space, the optimization routine does not allow all the labels to be spread optimally, which is unfortunate (in spite of a 0 spread cost to vertical displacement). And, since the label positions are numerically optimized, sometimes weird things even happen - like an errant tip label at one end or the other!

To address this, I today pushed a small update to phenogram which allows custom tip label spacing. I'm going to download the source from GitHub, but this function version can also be obtained by simply updating phytools from GitHub using devtools:

    xlab="relative time since the root",
    ylab="SVL (mm)")
## Optimizing the positions of the tip labels...

plot of chunk unnamed-chunk-3

What I did here is just supply evenly spaced vertical positions on the desired range in the order of the trait vector - in this case svl.


No comments:

Post a Comment

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