跟着Nature Genetics学画图:R语言ggtree可视化展示进化树时指定根节点

今天推文重复的图来自于 论文
Whole-genome resequencing of 445 Lactuca accessions reveals the domestication history of cultivated lettuce

image.png

今天试着重复的图片对应着的是论文中的Figure1b

image.png

数据集可以直接在论文里下载,但是原文存储的数据集是在excel里,我将其复制到一个文本文件里

截图如下

image.png
  • 这里有一个问题是数据集里展示的label有两个和图中的不一致
  • 还有一个问题是并不是所有的分支都带有枝长的信息,所以画图的时候会遇到警告信息
Warning message:
In fortify.phylo(data, ...) : 'edge.length' contains NA values...
## setting 'edge.length' to NULL automatically when plotting the tree...

所以最终呈现的图也是没有枝长信息的

首先是加载包

ggtree是用来做树展示
treeio是用来读取树,并对树进行操作

library(ggtree)
library(treeio)
library(ggplot2)
读取树文件并制定外类群
tree<-read.tree("NG/figure1b.tree")
root(tree,outgroup = "Helianthusannuus") -> tree1
展示进化树
ggtree(tree1,branch.length = "none")+
  geom_tiplab(fontface="italic")+
  xlim(0,15)
image.png
添加右侧表示分组的线段

为了方便我直接使用ggplot2里的annotate()函数了

ggtree(tree1,branch.length = "none")+
  geom_tiplab(fontface="italic")+
  xlim(0,15)+
  #geom_text(aes(label=node))+
  annotate(geom="segment",
           x=12,xend=12,y=12.5,yend=8)+
  annotate(geom="segment",
           x=12,xend=11.5,y=12.5,yend=12.5)+
  annotate(geom="segment",
           x=12,xend=11.5,y=8,yend=8)+
  annotate(geom="segment",
           x=12,xend=11.5,y=7.2,yend=7.2)+
  annotate(geom="segment",
           x=12,xend=11.5,y=6.8,yend=6.8)+
  annotate(geom="segment",
           x=12,xend=12,y=7.2,yend=6.8)+
  annotate(geom="segment",
           x=12,xend=11.5,y=6.2,yend=6.2)+
  annotate(geom="segment",
           x=12,xend=11.5,y=5.8,yend=5.8)+
  annotate(geom="segment",
           x=12,xend=12,y=6.2,yend=5.8)+
  annotate(geom = "text",x=12.5,y=10.5,label="GP1",hjust=0)+
  annotate(geom = "text",x=12.5,y=7,label="GP2",hjust=0)+
  annotate(geom = "text",x=12.5,y=6,label="GP3",hjust=0)
image.png
添加标尺信息

这里如何更改标尺信息的文字标签暂时没有搞明白,可以出图后编辑

ggtree(tree1,branch.length = "none")+
  geom_tiplab(fontface="italic")+
  xlim(0,15)+
  #geom_text(aes(label=node))+
  annotate(geom="segment",
           x=12,xend=12,y=12.5,yend=8)+
  annotate(geom="segment",
           x=12,xend=11.5,y=12.5,yend=12.5)+
  annotate(geom="segment",
           x=12,xend=11.5,y=8,yend=8)+
  annotate(geom="segment",
           x=12,xend=11.5,y=7.2,yend=7.2)+
  annotate(geom="segment",
           x=12,xend=11.5,y=6.8,yend=6.8)+
  annotate(geom="segment",
           x=12,xend=12,y=7.2,yend=6.8)+
  annotate(geom="segment",
           x=12,xend=11.5,y=6.2,yend=6.2)+
  annotate(geom="segment",
           x=12,xend=11.5,y=5.8,yend=5.8)+
  annotate(geom="segment",
           x=12,xend=12,y=6.2,yend=5.8)+
  annotate(geom = "text",x=12.5,y=10.5,label="GP1",hjust=0)+
  annotate(geom = "text",x=12.5,y=7,label="GP2",hjust=0)+
  annotate(geom = "text",x=12.5,y=6,label="GP3",hjust=0)+
  geom_treescale(x=14,y=1,width = 1,linesize = 2)

最后编辑一下文本

image.png

这里从上到下的顺序和原论文中可能有一些不一致,如果想要完全一致的话可以使用rotate()函数指定节点旋转

如果需要推文的示例数据和代码的话可以

  • 点赞
  • 点击在看
  • 后台回复 20210521

欢迎大家关注我的公众号

小明的数据分析笔记本

小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!

你可能感兴趣的:(跟着Nature Genetics学画图:R语言ggtree可视化展示进化树时指定根节点)