liamrevell / phytools

GNU General Public License v3.0
207 stars 56 forks source link

Line up tree node labeles #67

Closed AgustinPardo closed 4 years ago

AgustinPardo commented 4 years ago

Hello,

I execute the next lines to get a figure:

library(phytools)
library(mapdata)
gps<-read.csv("/home/agustin/workspace/covid-19/mapeo_arbol/gps_data.dat",header=TRUE)
rownames(gps) <- gps$ID
nwk=read.newick("/home/agustin/workspace/covid-19/mapeo_arbol/arbol_id_root_10.nwk")

obj<-phylo.to.map(nwk,gps[1:179,2:3],fsize=0.4,lwd=0.5,pts=FALSE,
                  direction="rightwards",database="worldHires", 
                  regions=c('Brazil', 'Colombia', 'Uruguay', 'Chile', 'Argentina', 'Peru',"Falkland"), 
                  rotate=FALSE)

I get this figure:

Screenshot from 2020-06-02 17-04-13

Do you know how to line up the tree node labels as you made in you figures:

Screenshot from 2020-06-02 17-28-16

Regards

Agustin

liamrevell commented 4 years ago

Agustin. The function plots your input tree, so most likely your input tree does not have tips that line up. If you want them to line up, you need to input an ultrametric tree to the function. If the current edge lengths don't mean anything (it looks like they all have the same length) you could use the arbitrary branch lengths of compute.brlen in the ape package. For instance:

 obj<-phylo.to.map(compute.brlen(nwk),gps[1:179,2:3],fsize=0.4,lwd=0.5,pts=FALSE,
                  direction="rightwards",database="worldHires", 
                  regions=c('Brazil', 'Colombia', 'Uruguay', 'Chile', 'Argentina', 'Peru',"Falkland"), 
                  rotate=FALSE)
AgustinPardo commented 4 years ago

That works perfectly! Many thanks!