1、准备工作:
ggtree是bioconducter下的包,所以先安装bioconductor, 然后安装ggtree:
source("https://bioconductor.org/biocLite.R")
biocLite()
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("ggtree")
做好的进化树nwk文件放在桌面,然后读取:
tree <- read.tree(file = "C:/Users/Mr.R/Desktop/tree.nwk")
library("ggtree")
library("ggplot2")
ggtree(tree,layout = "circular")#画出圆形进化树
library("ggtree")
library("ggplot2")
ggtree(tree,layout = "rectangular") #画出方的进化树
ggtree(tree, layout="fan", ladderize = FALSE, branch.length = "none") + geom_tiplab2(size=3) + theme(legend.position = "right")#画出带着标签的进化树
或者可以用以下代码也同样得到:
ggtree(tree, layout="circular", ladderize = FALSE, branch.length = "none") + geom_tiplab2(size=3) + theme(legend.position = "right")#画出带着标签的进化树
ggtree(tree) + geom_text(aes(label=node), hjust=-.3) + geom_tiplab(size=3)#获得带比对值的树
ggtree(tree) + geom_tiplab() + geom_hilight(node=8, fill="gold") +
geom_hilight(node=17, fill="purple") + geom_hilight(node = 2,fill = "red")#对某一个分支着色
ggtree(tree) + xlim(-5,30) + geom_tiplab() + geom_treescale() + geom_hilight(node=8, fill="gold") + geom_hilight(node=17, fill="purple")+geom_hilight(node = 2,fill = "red") #调整后再显示,标尺!
ggtree(tree) + xlim(-5,30)+ geom_tiplab() + geom_treescale()+ geom_hilight(node=8, fill="gold") + geom_hilight(node=17, fill="purple")+geom_hilight(node = 2,fill = "red") + geom_point(aes(shape=isTip, color=isTip), size=2.5) #对节点进行美化或添加标签
2、安装用newick方法来打开进化树,可用以标注bootstrap值
install.packages("treeio")
library(treeio)# 安装用newick方法来打开进化树,可用以标注bootstrap值。
tree <- read.newick("C:/Users/Mr.R/Desktop/tree.nwk", node.label="support")#node.label获值
ggtree(tree) + xlim(0,21) + geom_tiplab() + geom_treescale()+ geom_hilight(node=8, fill="gold") + geom_hilight(node=17, fill="purple")+geom_hilight(node = 2,fill = "red") + geom_point(aes(shape=isTip, color=isTip), size=2.5) + geom_text2(aes(subset=!isTip,label=support))#获得注释有bootstrap值的进化树
或者可以用标注来表示:
ggtree(tree) + xlim(-15,21) + geom_tiplab() + geom_treescale()+ geom_hilight(node=8, fill="gold") + geom_hilight(node=17, fill="purple")+geom_hilight(node = 2,fill = "red") + geom_text2(aes(subset=!isTip,label=support)) + geom_point2(aes(subset=!isTip,fill=cut(support, c(0, 700, 900, 1000))), shape=21, size=4) + theme_tree(legend.position=c(0.2, 0.3))