R ggtree根据分支长度注释节点

R ggtree annotate node in accordance with branch length

我有一个由 Newick 文件制作的系统发育树。

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))

Newick 文件是

(((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;

输出树是这样的

我想这样注释节点。 (按照分支长度)

您可以尝试使用geom_text2添加分支长度信息。

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)

情节