基因组数据绘图plot基因组

跟着Nature Plants学作图:R语言ggtree包展示进

2022-05-12  本文已影响0人  小明的数据分析笔记本

论文

The flying spider-monkey tree fern genome provides insights into fern evolution and arborescence

https://www.nature.com/articles/s41477-022-01146-6#Sec44

数据下载链接

https://doi.org/10.6084/m9.figshare.19125641

看了论文,提供了论文中所有树图的原始树文件,虽然没有提供代码,应该能利用原始数据模仿出来

今天的推文重复一下论文中的Figure4b

image.png

首先是读取树文件

library(ggtree)
library(treeio)

tree<-read.newick("data/20220512/phylogenetic trees/Fig4b_resequencing_tree.nwk",
                  node.label = "support")

最基本的树

ggtree(tree)
image.png

去掉枝长信息

ggtree(tree,branch.length = "none")
image.png

添加文字标签

ggtree(tree,branch.length = "none")+
  geom_tiplab(size=1.5)

添加表示Bootstrap值的点

ggtree(tree,branch.length = "none")+
  geom_tiplab(size=1.5)+
  geom_nodepoint(aes(size=support,x=x-0.5))

变成环形

ggtree(tree,
       branch.length = "none",
       layout = "circular")+
  geom_tiplab(size=3)+
  geom_nodepoint(aes(size=support,x=x-0.5),
                 color="#8f8fc3")
image.png

原文中的图好像还在文字间添加了虚线段

ggtree(tree,
       branch.length = "none",
       layout = "circular")+
  geom_tiplab(size=3,align = TRUE,offset = 1)+
  geom_nodepoint(aes(size=support,x=x-0.5),
                 color="#8f8fc3")

添加色块

ggtree(tree,
       branch.length = "none",
       layout = "circular")+
  geom_nodepoint(aes(size=support,x=x-0.5),
                 color="#8f8fc3")+
  geom_strip(taxa1 = "YN-8",
             taxa2 = "XZ-4",
             offset = 1.5,
             barsize = 12,
             extend = 0.5,
             color="#7c90c8")+
  geom_tiplab(size=3,align = TRUE,offset = 1)
image.png

把所有色块加上

ggtree(tree,
       branch.length = "none",
       layout = "circular")+
  geom_nodepoint(aes(size=support,x=x-0.5),
                 color="#8f8fc3")+
  geom_strip(taxa1 = "YN-8",
             taxa2 = "YN-3",
             offset = 2,
             barsize = 20,
             extend = 0.5,
             color="#7c90c8",
             label = "YN",
             offset.text = 3)+
  geom_strip(taxa1 = "XZ-4",
             taxa2 = "XZ-2",
             offset = 2,
             barsize = 20,
             extend = 0.5,
             color="#549e34",
             label = "XZ",
             offset.text = 3)+
  geom_strip(taxa1 = "Nepal-12",
             taxa2 = "Nepal-8",
             offset = 2,
             barsize = 20,
             extend = 0.5,
             color="#ebcc5f",
             label = "Nepal",
             offset.text = 3)+
  geom_strip(taxa1 = "FJ-11",
             taxa2 = "FJ-5",
             offset = 2,
             barsize = 20,
             extend = 0.5,
             color="#c3e5f5",
             label = "FJ/TW",
             offset.text = 3)+
  geom_strip(taxa1 = "HN-12",
             taxa2 = "HN-5",
             offset = 2,
             barsize = 20,
             extend = 0.5,
             color="#e95639",
             label = "HN",
             offset.text = 3)+
  geom_strip(taxa1 = "GX-5",
             taxa2 = "SC-6",
             offset = 2,
             barsize = 20,
             extend = 0.5,
             color="#e5914c",
             label = "GX/SC/GZ",
             offset.text = 3)+
  geom_tiplab(size=3,align = TRUE,offset = 1)
image.png

最外圈的文字方向和字体颜色暂时不知道如何用代码来调节,出图后编辑

最后是调整图例位置

ggtree(tree,
       branch.length = "none",
       layout = "circular")+
  geom_nodepoint(aes(size=support,x=x-0.5),
                 color="#8f8fc3")+
  geom_strip(taxa1 = "YN-8",
             taxa2 = "YN-3",
             offset = 2,
             barsize = 20,
             extend = 0.5,
             color="#7c90c8",
             label = "YN",
             offset.text = 3)+
  geom_strip(taxa1 = "XZ-4",
             taxa2 = "XZ-2",
             offset = 2,
             barsize = 20,
             extend = 0.5,
             color="#549e34",
             label = "XZ",
             offset.text = 3)+
  geom_strip(taxa1 = "Nepal-12",
             taxa2 = "Nepal-8",
             offset = 2,
             barsize = 20,
             extend = 0.5,
             color="#ebcc5f",
             label = "Nepal",
             offset.text = 3)+
  geom_strip(taxa1 = "FJ-11",
             taxa2 = "FJ-5",
             offset = 2,
             barsize = 20,
             extend = 0.5,
             color="#c3e5f5",
             label = "FJ/TW",
             offset.text = 3)+
  geom_strip(taxa1 = "HN-12",
             taxa2 = "HN-5",
             offset = 2,
             barsize = 20,
             extend = 0.5,
             color="#e95639",
             label = "HN",
             offset.text = 3)+
  geom_strip(taxa1 = "GX-5",
             taxa2 = "SC-6",
             offset = 2,
             barsize = 20,
             extend = 0.5,
             color="#e5914c",
             label = "GX/SC/GZ",
             offset.text = 3)+
  geom_tiplab(size=3,align = TRUE,offset = 1)+
  theme(legend.position = c(0.05,0.15))
image.png

示例数据可以到论文中去下载

欢迎大家关注我的公众号

小明的数据分析笔记本

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

上一篇下一篇

猜你喜欢

热点阅读