美文网首页重测序下游分析R语言做图生信可视化
跟着Nature microbiology学画图~R语言ggtr

跟着Nature microbiology学画图~R语言ggtr

作者: 小明的数据分析笔记本 | 来源:发表于2020-12-23 17:30 被阅读0次

今天要模仿的图片来自于论文 Core gut microbial communities are maintained by beneficial interactions and strain variability in fish。期刊是 Nature microbiology

image.png

今天重复的图片是Figure1中的聚类树图

image.png
论文中写道

Hierarchical clustering dendrogram with jackknife support (numbers on the branches; only values above 50 are shown in the tree).

所以论文中实际的数据做的是聚类分析,而并不是进化树。他这里做聚类分析也能够获得每个节点对应的支持率。这个如何实现我暂时还不知道。为了模仿这个图,下面的输入数据我直接使用进化树文件了,因为构建进化树的时候能够很方便的获得节点的支持率信息。

首先准备构建进化树需要用到的fasta格式序列文件

这里用到的数据集来自 网址 https://www.kuleuven.be/aidslab/phylogenybook/Data_sets.html

image.png

这本 The Phylogenetic Handbook second edition 不知道大家有没有电子版可以分享呀!

首先是做多序列比对,这里我使用mafft
mafft --auto ggtree_practice.fasta > ggtree_practice_aligned.fasta
构建进化树,我是用iqtree
iqtree -s ggtree_practice_aligned.fasta -bb 1000

得到树文件ggtree_practice_aligned.fasta.treefile

接下来是在R语言里的操作

首先是准备一个分组的数据文件

数据总共三列

  • 第一列是 构建进化树用到的fasta文件的序列名,这里注意列明用label,不要用其他
  • 第二列是分组信息,用来填充不同的颜色
  • 第三列也是分组信息,用来映射形状

第二列和第三列的列名就是图例上想显示什么就用什么

image.png
加载需要用到的包
library(ggtree)
library(treeio)
library(tidytree)
  • treeio用来读入进化树
  • tidytree用来将分组信息整合给进化树
  • ggtree用来可视化展示进化树
读入进化树和分组信息数据
tree<-read.newick("ggtree_practice_aligned.fasta.treefile",
                  node.label = "support")
tree<-read.newick("ggtree_practice_aligned.fasta.treefile",
                  node.label = "support")
d<-read.csv("ggtree_group_info.csv",header=T)
d
将树文件和分组信息整合到一起
trs<-full_join(tree,d,by='label')
去掉支持率小于50的信息
tree@data$support<-ifelse(tree@data$support<50,NA,tree@data$support)
最后一步就是画图了
ggtree(trs,layout = "circular",branch.length = "none")+
  #geom_tiplab(offset = 0.01)+
  geom_tippoint(aes(shape=Diet,color=Gut.compartment),
                size=5)+
  scale_shape_manual(values = c(16,17,18,15))+
  geom_text2(aes(label=support,angle=angle),hjust=-0.2)+
  scale_color_manual(values = c("#800080","#ff8000","#008080"),
                     name="Gut_compartment")+
  guides(color=guide_legend(order = 1))
image.png

以上代码的具体作用就不在这篇推文里进行介绍了,争取出一期视频介绍每个函数的作用。如果需要这篇推文的示例数据直接在文末留言就好了。
这里遇到一个问题是有没有办法给图例的文本填充不同的颜色呢?。欢迎大家在文末留言讨论这个问题呀!

参考资料

http://yulab-smu.top/treedata-book/chapter4.html

欢迎大家关注我的公众号
小明的数据分析笔记本

相关文章

网友评论

    本文标题:跟着Nature microbiology学画图~R语言ggtr

    本文链接:https://www.haomeiwen.com/subject/ossynktx.html