-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_figure2.R
160 lines (135 loc) · 6.06 KB
/
plot_figure2.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
################################################################################
# libraries #
################################################################################
library(tidyverse)
library(ape)
library(treeio)
library(ggtree)
library(patchwork)
################################################################################
# configurations #
################################################################################
# set factor levels
lvls <- c(
"West African",
"Kordofan",
"Nubian",
"Reticulated",
"Masai s. str.",
"Luangwa",
"South African",
"Angolan"
)
# set color palette
palette <- c(
"West African" = "#F0E442",
"Kordofan" = "#E69F00",
"Nubian" = "#D55E00",
"Reticulated" = "#CC79A7",
"Masai s. str." = "#009E73",
"Luangwa" = "#006046",
"South African" = "#56B4E9",
"Angolan" = "#0072B2"
)
################################################################################
# preparation #
################################################################################
# set working directory
setwd("~/documents/rcoimbra_phd/project_kenya")
# import metadata
metadata <- read_csv("metadata.csv")
# create tibble with samples information
sample.info <- metadata %>%
mutate(
taxonomy = case_when(
str_detect(taxonomy, regex("Giraffa camelopardalis peralta")) ~ "West African",
str_detect(taxonomy, regex("Giraffa camelopardalis antiquorum")) ~ "Kordofan",
str_detect(taxonomy, regex("Giraffa camelopardalis camelopardalis")) ~ "Nubian",
str_detect(taxonomy, regex("Giraffa reticulata")) ~ "Reticulated",
str_detect(taxonomy, regex("Giraffa tippelskirchi tippelskirchi")) ~ "Masai s. str.",
str_detect(taxonomy, regex("Giraffa tippelskirchi thornicrofti")) ~ "Luangwa",
str_detect(taxonomy, regex("Giraffa giraffa giraffa")) ~ "South African",
str_detect(taxonomy, regex("Giraffa giraffa angolensis")) ~ "Angolan",
TRUE ~ NA_character_
)
) %>%
mutate(taxonomy = fct_relevel(taxonomy, lvls))
# clean environment
rm(metadata)
################################################################################
# mtdna phylogeny #
################################################################################
# set working directory
setwd("~/documents/rcoimbra_phd/project_kenya/results/07_phylogeny_mtdna/")
# import tree
t1 <- read.iqtree("partitions.nex.treefile")
# remove outgroup
t1.pruned <- drop.tip(t1, "JN632674")
# check the node labels
#plot.phylo(as.phylo(t1.pruned), no.margin = TRUE, cex = 0.75)
#nodelabels(cex = 0.75, frame = "circle")
# create the basic plot
t1.plot <- ggtree(tr = t1.pruned, layout = "roundrect", ladderize = TRUE, size = 0.35)
# add taxonomy tibble to tree plot
t1.final <- t1.plot %<+% sample.info +
# adjust x-axis plot limit
xlim(0, 0.05) +
# add scale bar
geom_treescale(x = 0, y = 0, fontsize = 6.5 / .pt) +
# add tip labels
geom_tiplab(mapping = aes(color = taxonomy), align = TRUE, size = 5.2 / .pt, linesize = 0.25, key_glyph = draw_key_label) +
# add node points (support values)
geom_point2(mapping = aes(subset = as.numeric(sub("/.*", "", label)) >= 80 & as.numeric(sub(".*/", "", label)) >= 95 & !isTip), size = 1.2) +
# add branch labels (support values)
#geom_text2(mapping = aes(x = branch,
# label = label,
# subset = as.numeric(sub("/.*", "", label)) >= 80 & as.numeric(sub(".*/", "", label)) >= 95 & !isTip),
# vjust = -0.5,
# size = 1.8) +
# add legend
scale_color_manual("Taxonomy", labels = lvls, values = palette) +
theme(
legend.title = element_text(face = "bold", size = 10),
legend.text = element_text(size = 9), # face = "italic"
legend.key.size = unit(0.8, "line"),
legend.position = c(0.25, 0.88)
) +
guides(color = guide_legend(override.aes = list(size = 4, linetype = 0)))
################################################################################
# snp phylogeny #
################################################################################
# set working directory
setwd("~/documents/rcoimbra_phd/project_kenya/results/06_phylogeny_snp/")
# import tree
t2 <- read.iqtree("snps.sampled.min4.phy.varsites.phy.treefile")
# remove outgroup
t2.pruned <- drop.tip(t2, "WOAK")
# create the basic plot
t2.plot <- ggtree(tr = t2.pruned, layout = "roundrect", ladderize = TRUE, size = 0.35)
# add taxonomy tibble to tree plot
t2.final <- t2.plot %<+% sample.info +
# adjust x-axis plot limit
xlim(0, 0.01) +
# add scale bar
geom_treescale(x = 0, y = 0, fontsize = 6.5 / .pt) +
# add tip labels
geom_tiplab(mapping = aes(color = taxonomy), align = TRUE, size = 5.6 / .pt, linesize = 0.25) +
# add node points (support values)
geom_point2(mapping = aes(subset = as.numeric(sub("/.*", "", label)) >= 80 & as.numeric(sub(".*/", "", label)) >= 95 & !isTip), size = 1.2) +
# add legend
scale_color_manual("Taxonomy", labels = lvls, values = palette) +
theme(legend.position = "none")
################################################################################
# final plot #
################################################################################
# create composite plot
t2.final + t1.final #+ plot_annotation(tag_levels = "a")
# save plot in '.tiff' format
ggsave(
filename = "figure2.tiff",
path = "~/documents/rcoimbra_phd/project_kenya/figures/",
width = 170,
height = 233,
units = "mm",
dpi = 600
)