-
Notifications
You must be signed in to change notification settings - Fork 0
/
ggtree_plot.R
54 lines (43 loc) · 1.39 KB
/
ggtree_plot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# run this script in R version 3.3.2
# dir
rm(list=ls())
setwd("D:/my_research/populus_gene_family/")
# bash shell
# cat report_run.cafe | grep "# IDs of nodes" | cut -f 2 -d ":" | sed 's/$/;/' > xso_cafe.tre
# library
library(ggtree)
library(ggimage)
# load data
summary_node <- read.table("cafe/summary_run_node.txt", header = T, sep="\t")
tree1 <- read.tree(file = "r8s/r8s_ultrametric.tre")
tree2 <- read.tree(file = "cafe/xso_cafe.tre")
#p1<-ggtree(tree1) + geom_text(aes(label=node), hjust=-.3)+ geom_tiplab(size = 3, hjust=-0.3)
# data manipulation
p1 <- ggtree(tree1)
dat1 <- p1$data[c("node", "label")]
p2<-ggtree(tree2)
dat2 <- p2$data[c("node", "label")]
merge1 <- merge(dat1, dat2, by = "node")
merge2 <- merge(merge1, summary_node, by.x = names(merge1)[3], by.y = "Node")
# Expansion and Contraction data
EC <- merge2[c("Expansions", "Contractions", "node")]
#############
revts <- function (treeview)
{
x <- treeview$data$x
x <- x - max(x)
treeview$data$x <- x
treeview
}
# plot
fig1 <- ggtree(tree1) + geom_tiplab(size = 4)
pies <- nodepie(EC, cols=1:2, color = c("#00A8E8", "#E71D36"), alpha=.6)
fig1 <- inset(fig1, pies, width = 50, height = 50)
fig2 <- ggtree(tree1) + geom_tiplab(size = 4) + theme_tree2()
fig2 <- revts(fig2)
fig2 <- fig2 + scale_x_continuous(breaks=seq(-1200, 0, 200), labels=abs(seq(-1200, 0, 200)))
# save plot
pdf(file="tree_piechart.pdf", 12, 8)
fig1
fig2
dev.off()