A ggtree Script
this is the document to modify a tree
library(ggtree)
library("tidyr")
library(dplyr)
library("ggplot2")
library(ggstance)
library(ggsci)
library(extrafont)
library("yyplot")
tree1<-read.newick("rooted.nwk",node.label = "support")
tmp<-tree1@data[-1,]
data1<-read.table("countresult.txt",header = F,sep = "\t")
colnames(data1)<-c("support","type","num")
dat1<-spread(data1,key = "type",value = "num")
dat2<-dat1[1:39,]
dat1<-dat1[40:74,]
cols=pal_aaas()(4)
dat1$support<-gsub("X","",dat1$support)
tmp$support<-as.character(tmp$support)
dat1<-left_join(x = dat1,y=tmp,by="support")
dat2<-dat1[,-c(1,2,6)]
Begin to Plot
p<-ggtree(tree1)
p$data$x[1]<-0.05
p$data$x[2]<-0.05
p<-p+geom_tiplab(align = T)+theme_tree2()+xlim(c(0,0.2))
dat2<--dat2
dat2$node<-(-dat2$node)
bars<-nodebar(dat2,cols=1:4,position = "dodge",color = c(gain='red',expansion='orange',loss="black",reduction='grey'))
for (i in names(bars))
{
bars[[i]]<-bars[[i]]+coord_flip()
}
p1<-inset(p, bars, width=.01, height=2,hjust=.003)
pt<-p1 %<+% dat1+geom_nodelab(aes(label=current),nudge_x = 0.003,size=3)
╮( ̄▽ ̄)╭
Da Huo
huoda@ihb.ac.cn
Institute of hydrobiology,Chinese Academy of Science