R IN ACTION SELF-TUTORIAL-23 cladogram系统进化分枝图的绘制 2020-06-17

对于宏基因组数据进行最后进化分枝的绘制可以用GraPhlAn(http://segatalab.cibio.unitn.it/tools/graphlan/index.html)绘制,或者LEfSe的结果中也会得到相应的图。R中可以用microbiomeViz来实现对应的图。
1、先看最终的结果:

image.png

2、实现过程:

source("https://bioconductor.org/biocLite.R")
biocLite("ggtree")
devtools::install_github("lch14forever/microbiomeViz")
library(microbiomeViz)#安装microbiomeViz包
library(ggtree)
df <- read.table("http://bailab.genetics.ac.cn/markdown/R/microbiomeViz/merged_abundance_table.txt", head=TRUE, stringsAsFactors = FALSE) # 直接在网上加载测试数据
df #显示获取的数据,为如下
image.png

image.png
dat <- data.frame(V1=df[,1], V2=rowMeans(df[,-1]), stringsAsFactors = FALSE) ## 计算均值用于呈现结点大小,形成dataframe, The function data.frame() creates data frames, tightly coupled collections of variables which share many of the properties of matrices and of lists, used as the fundamental data structure by most of R's modeling software.
tr <- parseMetaphlanTSV(dat, node.size.offset=2, node.size.scale=0.8) #物种和丰度生成, parse a MetaPhlan table to a tree object 
p <- tree.backbone(tr, size=0.5) #basic tree (backbone) plotting utility
p #画出骨架如下图 
image.png
lefse_lists = data.frame(node=c('s__Haemophilus_parainfluenzae','p__Proteobacteria', 'f__Veillonellaceae','o__Selenomonadales', 'c__Negativicutes', 's__Streptococcus_parasanguinis',
 'p__Firmicutes','f__Streptococcaceae', 'g__Streptococcus','o__Lactobacillales', 'c__Bacilli','s__Streptococcus_mitis'), color=c(rep('darkgreen',6), rep('red','6')), stringsAsFactors = FALSE) # 读取需要颜色标注的差异物种列表,本质上是两列和颜色对应表
p <- clade.anno(p, lefse_lists, alpha=0.3) # 注释树, annotate a ggtree plot to highlight certain clades
p#显示最终的结果
image.png

你可能感兴趣的:(R IN ACTION SELF-TUTORIAL-23 cladogram系统进化分枝图的绘制 2020-06-17)