-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplot_results.R
52 lines (43 loc) · 2.07 KB
/
plot_results.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
#
# This R script plots the ancestral chromosome numbers estimated
# by a ChromoSSE RevBayes analysis.
#
# Install the RevGadgets R package from:
# https://github.com/revbayes/RevGadgets
#
library(RevGadgets)
library(ggplot2)
# plot the ancestral states tree generated by RevBayes
p = plot_ancestral_states("examples/aristolochia/data/aristolochia_ancestral_states.tree",
size=0.4,
include_start_states=TRUE,
summary_statistic="MAPChromosome",
tip_label_size=3,
tip_label_offset=0.4,
tip_label_italics=TRUE,
node_label_size=2,
node_label_nudge_x=0.1,
shoulder_label_size=2,
alpha=.3)
# using ggtree and ggplot2 functions we can now add all sorts of details
# to our figure:
# let's add a time scale
root_age = 10.0
p = p + scale_x_continuous(breaks=c(10, 5, 0), minor_breaks=c(2.5, 7.5), labels=c("0", "5", "10"))
p = p + theme(panel.grid.major = element_line(color="darkgrey", size=.2, linetype="dashed"),
panel.grid.minor = element_line(color="grey", size=.2, linetype="dashed"),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
legend.position="left")
# annotate some of the clades
p = p + geom_cladelabel(node=60, label="Isotrema", align=TRUE, offset=5.0, size=2)
p = p + geom_cladelabel(node=36, label="Aristolochia", align=TRUE, offset=5.0, size=2)
# add an arrow to show a possible dysploid speciation event
arrow_xend = 9.65
arrow_yend = 26.75
p = p + geom_segment(x=arrow_xend-0.4, y=arrow_yend+0.6, xend=arrow_xend, yend=arrow_yend,
size=0.5, color="grey35", arrow=arrow(length=unit(0.2, "cm"), type="open", angle=30), inherit.aes=FALSE)
# set the final dimensions and write pdf
p = p + coord_cartesian(xlim = c(0, 16.5))
print(p)
ggsave("examples/aristolochia/data/aristolochia_ancestral_states.pdf", width = 11, height = 9)