系統(tǒng)發(fā)育樹幾乎是基因家族文章的必備圖割岛,一個好看的樹圖的確能給文章增色不少羊初,一般的用戶可能只使用MEGA繪圖啸盏,進階一點的便會使用iTOL,evolview等2款在線繪圖平臺耿导,然而這并不是本文所要介紹的重點声怔,本節(jié)來介紹如何使用ggtree來繪制系統(tǒng)發(fā)育樹,自從有了ggtree進化樹繪制從未如此簡單
加載R包
library(tidyverse)
library(ggtree)
library(treeio)
library(ggsci)
讀入數(shù)據(jù)
node.label = "support"將node label解析為support value舱呻,另存為樹注釋數(shù)據(jù)
tree <- read.newick("tree.nwk",node.label = "support")
group <- read.table("group.xls",header = T,row.names = 1)
group1 <- split(row.names(group),group$Group)
數(shù)據(jù)可視化
先繪制出樹的主干
p <- groupOTU(tree,group1) %>%
ggtree(branch.length = "none",
linetype=1,size=0.8,ladderize = T,aes(color=group))
p
根據(jù)節(jié)點信息給分組添加背景顏色
p1 <- p + geom_text(aes(label=node), hjust=-3,size=3)+
scale_color_nejm()+labs(color="")+
geom_hilight(node=63,fill="#1E90FF",type="rect",alpha=0.6)+
geom_hilight(node=36,fill="#FF8C00",type="rect",alpha=0.6)+
geom_hilight(node=43,fill="#4DAF4A",type="rect",alpha=0.6)+
geom_hilight(node=47,fill="#984EA3",type="rect",alpha=0.6)
添加置信度信息
p2 <- p1 + geom_point2(aes(subset=!isTip,
fill=support),shape=21,size=2)+
scale_fill_continuous(low='green',high='red')
根據(jù)節(jié)點繪制分組色條醋火,此處的參數(shù)很多,先無需全部調(diào)整只需要確定色條的起始與終止位點即可箱吕,因為后續(xù)我們需要將其轉(zhuǎn)化為圓形
p3 <- p2 + geom_strip(62,49,label = "Group I", align = T, alpha=.8,family="Times",
fontsize=5,offset = 7, color = "#984EA3",offset.text = 2 ,
hjust="center",barsize = 5,extend = 1)+
geom_strip(44,46,label = "Group II", align = T, alpha=.8,family="Times",
fontsize=5,offset = 7, color ="#4DAF4A",offset.text = 2 ,
hjust="center",barsize = 5,extend = 1,angle=66)+
geom_strip(40,1,label = "Group III", align = T, alpha=.8,family="Times",
fontsize=5,offset = 7, color = "#FF8C00",offset.text = 2 ,
hjust="center",barsize = 5,extend = 1,angle=0)+
geom_strip(63,66,label = "Group V", align = T, alpha=.8,family="Times",
fontsize=5,offset = 7, color = "#1E90FF",offset.text = 2 ,
hjust="center",barsize = 5,extend = 1,angle=-50)
經(jīng)過上面的步驟我們得到了給分組添加背景及添加分組色條的位置信息芥驳,下面讓我們從一開始就將圖形布局展示為圓形
完整版代碼
pp3 <- groupOTU(tree,group1) %>%
ggtree(branch.length = "none",layout = "circular",
linetype=1,size=0.8,ladderize = T,aes(color=group))+
#geom_text(aes(label=node), hjust=-3,size=3) +
geom_tiplab(size=3,family="Times",hjust = -0.1)+
scale_color_nejm()+labs(color="")+
geom_hilight(node=63,fill="#1E90FF",type="rect",alpha=0.6)+
geom_hilight(node=36,fill="#FF8C00",type="rect",alpha=0.6)+
geom_hilight(node=43,fill="#4DAF4A",type="rect",alpha=0.6)+
geom_hilight(node=47,fill="#984EA3",type="rect",alpha=0.6)+
geom_point2(aes(subset=!isTip,fill=support),shape=21,size=2)+
scale_fill_continuous(low='green',high='red')+
geom_strip(62,49,label = "Group I", align = T, alpha=.8,family="Times",
fontsize=5,offset = 7, color = "#984EA3",offset.text = 2 ,
hjust="center",barsize = 5,extend = 1)+
geom_strip(44,46,label = "Group II", align = T, alpha=.8,family="Times",
fontsize=5,offset = 7, color ="#4DAF4A",offset.text = 2 ,
hjust="center",barsize = 5,extend = 1,angle=66)+
geom_strip(40,1,label = "Group III", align = T, alpha=.8,family="Times",
fontsize=5,offset = 7, color = "#FF8C00",offset.text = 2 ,
hjust="center",barsize = 5,extend = 1,angle=0)+
geom_strip(63,66,label = "Group V", align = T, alpha=.8,family="Times",
fontsize=5,offset = 7, color = "#1E90FF",offset.text = 2 ,
hjust="center",barsize = 5,extend = 1,angle=-50)+
labs(fill = "bootstrap")
ggsave(pp3,file="tree.png",width =8,height =7,units="in",dpi=300)
pp3
library(ggpubr)
tibble(函數(shù)= c("geom_strip", "geom_tiplab()","geom_fruit()",
"offset.text","extend","offset","hjust=center"),
功能= c("根據(jù)節(jié)點添加外部條帶,后跟節(jié)點位置信息",
"設(shè)置標簽顯示","繪制條形","調(diào)整label位置",
"調(diào)整條帶之間間距","設(shè)置距離節(jié)點的位置","將lable居中放置")) %>%
ggtexttable(rows = NULL, theme = ttheme("mBlue"))