1

I have a phylogenetic tree made by a Newick file.

library(tidyverse)
library(ggtree)

tree <- read.tree("newick_test.nwk")

p1 <- ggtree(tree) + geom_tree() + theme_tree2() + coord_cartesian(xlim = c(0,40), ylim = c(0,19))

and the Newick file is

(((15L55MS_1001A7:32411,(15LSRMS_5001H4:94544,15R36Fb_5001F1:16481):15:0):9,(15L49Fb_2001E2:3430,15R126Fb_1001B4:10443):10:0):5,((15LNMS_2001H5:4859,15C9Fb_6001E2:18771):10:0,(15L36Fb_001A6:5646,(15R76Fb_6001A8:11866,15L21Fb_1001D4:11563):14:0):12:0):7):0;

The output tree is like this.

enter image description here

I want to annotate the nodes like this. (in accordance with branch length)

enter image description here

SG Kwon
  • 163
  • 1
  • 9

1 Answers1

2

You can try using geom_text2 to add the branch length information.

library(ggtree)

tree <- read.tree(text = "(((15L55MS_1001A7:32411,(15LSRMS_5001H4:94544,15R36Fb_5001F1:16481):15:0):9,(15L49Fb_2001E2:3430,15R126Fb_1001B4:10443):10:0):5,((15LNMS_2001H5:4859,15C9Fb_6001E2:18771):10:0,(15L36Fb_001A6:5646,(15R76Fb_6001A8:11866,15L21Fb_1001D4:11563):14:0):12:0):7):0;")

ggtree(tree) + 
  geom_tree() + 
  theme_tree2() + 
  coord_cartesian(xlim = c(0, 40), ylim = c(0, 19)) +
  geom_text2(aes(label = branch.length), hjust = -.3)

Plot

phylogenetic tree with branch length labels

Ben
  • 28,684
  • 5
  • 23
  • 45