繪制進化樹的方法有很多,入門的MEGA,iTOL,evolview等,但是沒有一個如ggtree這般高效簡單,輕輕松松繪制高端進化樹,廢話不多說,直接看代碼
喜歡的小伙伴可以關注公眾號R語言數據分析指南獲得原始數據,在此先行拜謝了
rm(list = ls())
library(pacman)
pacman::p_load(ggplot2,ggstar,ggtreeExtra,ggtree,
treeio,ggnewscale,ggsci); options(warn = -1)
tree <- read.newick("tree.nwk",node.label = "support")
#node.label = "support"將node label解析為support value,另存為樹注釋數據
group <- read.table("tree_group.txt",header = T,sep="\t")
#讀入分組文件用于繪制條行圖,并按分組添加顏色
group_file <- read.table("tree_group.txt",header = T,row.names = 1)
groupInfo <- split(row.names(group_file), group_file$Group)
tree <- groupOTU(tree, groupInfo)
ggtree(tree,branch.length = "none",layout = "circular",
linetype=1,size=1,ladderize = F,aes(color=group))+
#geom_text(aes(label=node), hjust=-3,size=1) +
#展示節(jié)點信息,并根據節(jié)點信息添加外圈分組
scale_color_npg()+guides(color=FALSE)+
#guides(color=FALSE) 移除圖例
geom_fruit(data=group,
geom=geom_bar,
mapping=aes(y=Sample, x=Length,fill=Group),
orientation="y",stat="identity",color="white")+
scale_fill_npg()+labs(fill = "")+new_scale_fill()+
geom_strip(53,116, #geom_strip()根據節(jié)點添加外部條帶,后跟節(jié)點位置信息
label = "Group I", align = T, alpha=.8,family="Times",
fontsize=4,offset = 3, color = "orange",offset.text = 2 ,
hjust="center",barsize = 4,extend = 0.5)+
#offset.text調整label位置;extend調整條帶之間間距;offset設置距離節(jié)點的位置;
#hjust="center"將lable居中放置
geom_strip(35,52,
label = "Group II", align = T, alpha=.8,family="Times",
offset = 3, color = "green",offset.text = 2 ,fontsize=4,
hjust="center",barsize = 4,extend = 0.5,angle = 45)+
geom_strip(20,34,
label = "Group III", align = T, alpha=.8,family="Times",
offset = 3, color = "red",offset.text = 2 ,fontsize=4,
hjust="center",barsize = 4,extend = 0.5)+
geom_strip(1,19,
label = "Group IV", align = T, alpha=.8,family="Times",
offset = 3, color = "blue",offset.text = 2 ,fontsize=4,
hjust="center",barsize = 4,extend = 0.5,angle=-60)+
#geom_tiplab(hjust = -.5,size=3,fontface="plain")+
#設置標簽顯示
geom_point2(aes(subset=!isTip,fill=support),
shape=21,size=2)+
scale_fill_continuous(low='green', high='red')+
labs(fill = "bootstrap")

tree.jpeg
參考:https://rdrr.io/bioc/ggtree/man/geom_strip.html
https://bioconductor.org/packages/devel/bioc/vignettes/ggtreeExtra/inst/doc/ggtreeExtra.html
http://yulab-smu.top/treedata-book/
示例文件: https://pan.baidu.com/s/1V2xo7rQQMDFIlXY5tJCUQQ
提取碼: gr2t