前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >跟着Nature Plants学作图:R语言ggtree包展示进化树

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

作者头像
用户7010445
发布2022-05-23 15:56:10
2.8K0
发布2022-05-23 15:56:10
举报
文章被收录于专栏:小明的数据分析笔记本

论文

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

首先是读取树文件

代码语言:javascript
复制
library(ggtree)
library(treeio)

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

最基本的树

代码语言:javascript
复制
ggtree(tree)

这样的树形也是可以的吗?不太懂

去掉枝长信息

代码语言:javascript
复制
ggtree(tree,branch.length = "none")

image.png

添加文字标签

代码语言:javascript
复制
ggtree(tree,branch.length = "none")+
  geom_tiplab(size=1.5)

添加表示Bootstrap值的点

代码语言:javascript
复制
ggtree(tree,branch.length = "none")+
  geom_tiplab(size=1.5)+
  geom_nodepoint(aes(size=support,x=x-0.5))

变成环形

代码语言:javascript
复制
ggtree(tree,
       branch.length = "none",
       layout = "circular")+
  geom_tiplab(size=3)+
  geom_nodepoint(aes(size=support,x=x-0.5),
                 color="#8f8fc3")

image.png

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

代码语言:javascript
复制
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")

添加色块

代码语言:javascript
复制
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

把所有色块加上

代码语言:javascript
复制
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

最外圈的文字方向和字体颜色暂时不知道如何用代码来调节,出图后编辑,这里怎们把树旋转成和论文里一样暂时想不到办法了

最后是调整图例位置

代码语言:javascript
复制
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

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-05-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小明的数据分析笔记本 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 论文
  • 数据下载链接
  • 首先是读取树文件
  • 最基本的树
  • 去掉枝长信息
  • 添加文字标签
  • 添加表示Bootstrap值的点
  • 变成环形
  • 原文中的图好像还在文字间添加了虚线段
  • 添加色块
  • 把所有色块加上
  • 最后是调整图例位置
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档