简体   繁体   中英

How can I adjust the position of tip labels relative to tree tips on a phylogenetic tree?

I am trying to create a figure of a map of a continuous trait onto a phylogenetic tree using the ape and phytools packages in R for a publication. An example code of what I am trying to produce is as follows:

library("ape")
library("phytools")
orig_tree<-rtree(n=350)
plot(orig_tree)
values<-data.frame("residuals"=runif(350,min=-1,max=1),row.names=orig_tree$tip.label)
values<-setNames(values$residuals,rownames(values))
residualsignalfit<-fastAnc(orig_tree,values,vars=TRUE,CI=TRUE)
obj<-contMap(orig_tree,values,plot=FALSE)
plot(obj,type="fan",fsize=.1,lwd=0.5)

The only difference is the terminal of the branches are all the same length because they are all living taxa, but this works well enough to illustrate the problem I am having. I have a large number of taxa in this tree, and as a result I have to shrink the text down fairly small using the fsize= argument to make them legible. However, as you can see from the example code, doing so causes the ends of each species name to be obscured by the outline for the phylogenetic tree . I have tried removing the outline but it makes the heatmap of the phylogeny very hard to read. I have been unable to find any way to reduce the thickness of the outline, it seems to be automatically generated.

I also tried adding the cex command to plot(obj...) , but it has no effect on the produced tree at all.

What I am trying to figure out how to do is how to position the tip labels in order to make them more legible and not covered up by the outline for the tree. I cannot simply add a space in front of each terminal using the dplyr mutate function or something like that because the position of the taxon name is not always consistent, sometimes the left side of the name is attached to the tip and other times it is the right side. I have tried not plotting the data as a fan, but this ends up creating a figure with a huge amount of dead space due to the fact I have some very deep splits within the tree (basically plotting the figure as a right-facing tree results in half of the figure being dead space because my taxa diverged in the Mesozoic but only speciated after the KT boundary).

Instead of shrinking the text down, you can scale the tree up. You can export the plot as image with a specific width and height. Setting both to 20 should make all tip labels legible.

Something like

setEPS()
postscript("output.eps", width = 20, height = 20)
plot(obj,type="fan",lwd=0.5)
dev.off()

This saves the plot to output.eps instead of showing it in the default viewer. So it is not restricted by the screen size. You still need to fiddle around with the best values of lwd and fsize , but in my experience it is much easier, when you have a big canvas.

Edit: Sorry, the unit of width and height is inches not pixels. So rather set it to 10 or 20.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM