Search code examples
rphylogeny

How display length of branches in phylogenetic tree


Here I have code that draw simple phylogenetic tree from newick format:

library(ape)
t<-read.tree(text="(F:4,(  (D:2,E:2):1,(C:2,(B:1,A:1):1):1):1);")
plot(t,use.egde.length=TRUE)

i am"displaying" correct length of branches, but i want all branch to have labal with it. enter image description here

edit: i want my plot to look like this: enter image description here I was searching documentation, but I cannot find method to display length of branch in R. How can i do this ?


Solution

  • You can do it by extracting edge lengths and using edgelabels().

    # Load package
    library(ape)
    
    # Create data
    t <- read.tree(text="(F:4,((D:2,E:2):1,(C:2,(B:1,A:1):1):1):1);")
    plot(t)
    edgelabels(t$edge.length, bg="black", col="white", font=2)