||
#参考https://www.jianshu.com/p/bd3119a4dcd5 #导出qiime2的树文件和taxonomy文件,并用ggtree美化树 #根据qiime2计算的rooted-tree.qza,taxonomy.qza 导出数据,画系统发育树 # 由于两个数据的hash码顺序是不同的,需要重排序 # 根据tree数据对matedata排序并重构外部数据 require(readr) require(treeio) require(ggtree) require(tidyr) require(dplyr) require(tidytree) matedata <- read_tsv("taxonomy.tsv") tree <- read.newick("tree.nwk") match_Tax <- matedata[match(tree$tip.label, matedata$`Feature ID`), ] df <- data.frame(lable = tree$tip.label, Taxon = match_Tax$Taxon) df <- separate(df, Taxon, into = c("K", "P", "C","O","F","G", "S"), sep = ";") # 用%<+%传入外部数据,并用Taxon做tiplabel P_tree <- ggtree(tree, size=0.8, branch.length="none", aes(color = P), layout = "circular") %<+% df + # 按照门对tiplab上色 geom_tiplab2(aes(label = G), size = 1,hjust = -.01) + # 利用负号,生成中空的树 xlim(-0.5, NA) + # 限定画布大小 xlim_tree(1.2) P_tree ggsave(P_tree, file="tree.jpg", width=10, height=10,dpi = 300)
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-23 01:50
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社