基因家族分析构建系统发育树进化树可视化

用ggtree和ggimage对nwk进化树进行美化 2020-

2022-04-16  本文已影响0人  RashidinAbdu
image.png

一、对做好的nwk进化树进行簇标注、分组和美化:

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

1. 数据:做好的nwk进化树:

今天用做好的nwk进化树(即:用MEGA构建的系统进化树或基因树)为基础,下面的部分复制存到txt里,文件类型改为.nwk,即可。

image.png
((((((((('Roseburia hominis A2-183T (AJ270482)','Roseburia intestinalis strain L1-82T (AJ312385)'),'Roseburia faecis M721T (AY305310)'),'Roseburia cecicola ATCC 33874T(L14676)'),'Roseburia inulinivorans strain A2-194T (AJ270473)'),('Agathobacter ruminis strain JK623T (KT229569)','Agathobacter rectalis ATCC 33656T (NR 074634)')),('Pseudobutyrivibrio xylanovorans strain Mz5T (AJ428548)','Pseudobutyrivibrio ruminis DSM 9787T (X95893)')),('Falcatimonas natans DSM 22923T (AB298726)','Lachnobacterium bovis strain LRC 5382T (AF298663)')),(Strain_2710,('Kineothrix alysoides strain KNHs209T (KX356505)','Eisenbergiella tayi strain B086562T (KF814111)'))),'Coprococcus comes strain ATCC 27758T (EF031542)',(('Coprococcus catus strain VPI-C6-61T (AB038359)','Coprococcus eutactus strain ATCC 27759T (EF031543)'),('Lachnospira pectinoschiza ATCC 49827T (L14675)','Lachnospira multipara ATCC 19207T (AH000856)')));

2. 需要的包的安装和具体实现:

install.packages("BiocManager")
BiocManager::install("ggtree")
library(ggtree)

安装其他附包:

install.packages('pacman')
install.packages('ggstar')
install.packages('ggnewscale')
install.packages('ggsci')
library(ggtree)
library( ggplot2)
library(ggstar )
library( ggtreeExtra)
library(treeio )
library(ggnewscale )
library(ggsci )
tree <- read.newick("tree.nwk" )#读取进化树
ggtree(tree,branch.length = "none",layout = "circular",
       linetype=1,size=1,ladderize = F)#查看进化树
image.png
p1<-ggtree(tree,branch.length = "none",layout = "circular", linetype=1,size=1,ladderize = F )
p1<-p1+geom_text(aes(label=node), hjust=-3,size=2) 
p1
image.png
pc1<-p1+geom_strip(30,31, label = "Group I", align = T, alpha=.8,family="Times", fontsize=4,offset =2, color = "brown",offset.text = 2 ,hjust="center",barsize = 4,extend = 0.3)+geom_strip(8,28, label = "Group II", align = T, alpha=.8,family="Times", fontsize=4,offset = 2, color = "red",offset.text = 2 ,hjust="center",barsize = 4,extend = 0.3)+geom_strip(11,19, label = "Group III", align = T, alpha=.8,family="Times", fontsize=4,offset = 2, color = "blue",offset.text = 2 ,hjust="center",barsize = 4,extend = 0.3)
pc1
image.png
pc2<-pc1+geom_hilight(node=23, fill="red")+geom_hilight(node=32, fill="lightblue")+geom_hilight(node=34, fill="yellow")
pc2
image.png
p1<-ggtree(tree,branch.length = "none",layout = "circular", linetype=1,size=1,ladderize = F )
p1<-p1+geom_text(aes(label=node), hjust=-3,size=2) 
p1
image.png
p2<-p1 +geom_hilight(node=29, fill="red")+geom_hilight(node=34, fill="green")
p2<-p2+geom_hilight(node=32, fill="blue")+geom_hilight(node=31, fill="#FF00FF")
p2<-p2+geom_hilight(node=30, fill="#32CD99")+geom_hilight(node=25, fill="#38B0DE")
p2
image.png
p3<-p2+ geom_strip(31,30, label = "Group I", align = T, alpha=.8,fontsize=4,offset = 1.5,color = "red",offset.text =3 ,hjust="center",barsize = 2,extend = 1)
p3<-p3+ geom_strip(25,29, label = "Group II", align = T, alpha=1.8,fontsize=4,offset = 1.5,, color = "#2F2F4F",offset.text =3 ,hjust="center",barsize = 2,extend = 1)
p3<-p3+ geom_strip(27,27, label = "Group III", align = T, alpha=1.8,fontsize=4,offset = 1.5, color = "blue",offset.text =3 ,hjust="center",barsize = 2,extend = 1)
p3<-p3+ geom_strip(32,33, label = "Group IV", align = T, alpha=1.8,fontsize=4,offset = 1.5, color = "orange",offset.text =3 ,hjust="center",barsize = 2,,extend = 1)
p3<-p3+ geom_strip(34,36, label = "Group V", align = T, alpha=1.8,fontsize=4,offset = 1.5, color = "#DB7093",offset.text =3 ,hjust="center",barsize = 2,,extend = 1)
p3

得到:

image.png
p1<-ggtree(tree,branch.length = "none",layout = "circular", linetype=1,size=1,ladderize = F )
p1
image.png
p2<-p1 +geom_hilight(node=29, fill="red")+geom_hilight(node=34, fill="green")
p2<-p2+geom_hilight(node=32, fill="blue")+geom_hilight(node=31, fill="#FF00FF")
p2<-p2+geom_hilight(node=30, fill="#32CD99")+geom_hilight(node=25, fill="#38B0DE")
p2
image.png
p3<-p2+ geom_strip(31,30, label = "Group I", align = T, alpha=.8,fontsize=4,offset = 1.5,color = "red",offset.text =3 ,hjust="center",barsize = 2,extend = 1)
p3<-p3+ geom_strip(25,29, label = "Group II", align = T, alpha=1.8,fontsize=4,offset = 1.5,, color = "#2F2F4F",offset.text =3 ,hjust="center",barsize = 2,extend = 1)
p3<-p3+ geom_strip(27,27, label = "Group III", align = T, alpha=1.8,fontsize=4,offset = 1.5, color = "blue",offset.text =3 ,hjust="center",barsize = 2,extend = 1)
p3<-p3+ geom_strip(32,33, label = "Group IV", align = T, alpha=1.8,fontsize=4,offset = 1.5, color = "orange",offset.text =3 ,hjust="center",barsize = 2,,extend = 1)
p3<-p3+ geom_strip(34,36, label = "Group V", align = T, alpha=1.8,fontsize=4,offset = 1.5, color = "#DB7093",offset.text =3 ,hjust="center",barsize = 2,,extend = 1)
p3
image.png

二、对做好的nwk进化树用图片进行标注(比如物种类型等):

install.packages('ggimage')#安装ggimage包
install.packages('gridSVG')

1.作树:

layout选项(即进化树展示类型):

'rectangular', 'dendrogram', 'slanted', 'ellipse', 'roundrect', 'fan', 'circular', 'inward_circular', 'radial', 'equal_angle', 'daylight' ,'ape'

p1<-ggtree(tree,branch.length = "none",layout ='rectangular' , linetype=1,size=1,ladderize = F )
p1
image.png
p1<-ggtree(tree,branch.length = "none",layout ='dendrogram' , linetype=1,size=1,ladderize = F )
p1
image.png
p1<-ggtree(tree,branch.length = "none",layout ='slanted' , linetype=1,size=1,ladderize = F )
p1
image.png image.png
library(ggimage)
library(ggtree)

nwk <- "((((bufonidae, dendrobatidae), ceratophryidae), (centrolenidae, leptodactylidae)), hylidae);"
x = read.tree(text = nwk)

pg<-ggtree(x) + xlim(NA, 7) + ylim(NA, 6.2) 
pg1<-pg+ geom_tiplab(aes(image=paste0("C:/Users/Mr.R/Documents/Rfigures/", label, '.jpg')),   geom="image", offset=2, align=2, size=.2)  
pg1<-pg1+geom_tiplab(geom='label', offset=1, hjust=.5) 
pg1<-pg1+geom_image(x=.8, y=5.5, image="C:/Users/Mr.R/Documents/Rfigures/frog.jpg", size=0.21)#添加图上标签,其实可以不加
pg1

得到:

image.png
library(ggimage)
library(ggtree)

nwk <- "((((bufonidae, dendrobatidae), ceratophryidae), (centrolenidae, leptodactylidae)), hylidae);"
x = read.tree(text = nwk)

pg<-ggtree(x) + xlim(NA, 7) + ylim(NA, 6.2) 
pg1<-pg+ geom_tiplab(aes(image=paste0("C:/Users/Mr.R/Documents/Rfigures/", label, '.jpg')),   geom="image", offset=2, align=2, size=.2)  
pg1<-pg1+geom_tiplab(geom='label', offset=1, hjust=.5) 
pg1

得到:

image.png
library(ggtree)

nwk <- "((((((((('Roseburia hominis A2-183T (AJ270482)','Roseburia intestinalis strain L1-82T (AJ312385)'),'Roseburia faecis M721T (AY305310)'),'Roseburia cecicola ATCC 33874T(L14676)'),'Roseburia inulinivorans strain A2-194T (AJ270473)'),('Agathobacter ruminis strain JK623T (KT229569)','Agathobacter rectalis ATCC 33656T (NR 074634)')),('Pseudobutyrivibrio xylanovorans strain Mz5T (AJ428548)','Pseudobutyrivibrio ruminis DSM 9787T (X95893)')),('Falcatimonas natans DSM 22923T (AB298726)','Lachnobacterium bovis strain LRC 5382T (AF298663)')),(Strain_2710,('Kineothrix alysoides strain KNHs209T (KX356505)','Eisenbergiella tayi strain B086562T (KF814111)'))),'Coprococcus comes strain ATCC 27758T (EF031542)',(('Coprococcus catus strain VPI-C6-61T (AB038359)','Coprococcus eutactus strain ATCC 27759T (EF031543)'),('Lachnospira pectinoschiza ATCC 49827T (L14675)','Lachnospira multipara ATCC 19207T (AH000856)')));
"
x = read.tree(text = nwk)

pg<-ggtree(x)
pg1<-pg+ geom_tiplab(aes(image=paste0("C:/Users/Mr.R/Documents/Rfigures/", label, '.jpg')),   geom="image", offset=11, align=2)  
pg1<-pg1+geom_tiplab(geom='label', offset=1, hjust=0.12) 
pg1<-pg1+xlim(-11, 21) + ylim(NA, 22) 
pg1

得到:

image.png

或者可以直接读取nwk文件,然后添加图片:

library(ggtree)
tree <- read.newick("tree.nwk" )#读取进化树
#加载安装好的包
library(ggimage)
library(ggtree)

pg<-ggtree(tree)#绘制基本进化树并展示
pg

pg1<-pg+ geom_tiplab(aes(image=paste0("C:/Users/Mr.R/Documents/Rfigures/", label, '.jpg')),   geom="image", offset=7, align=2)  #制定标注图片的位置,offset来制定与树枝的距离
pg1<-pg1+geom_tiplab(geom='label', offset=1, hjust=0.12) 
pg1<-pg1+xlim(-1, 19) + ylim(-1, 19) #制定图片的大小
pg1

得到:

image.png
上一篇 下一篇

猜你喜欢

热点阅读