-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLaTree.R
More file actions
121 lines (103 loc) · 3.53 KB
/
LaTree.R
File metadata and controls
121 lines (103 loc) · 3.53 KB
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
# load required packages
library(ape)
library(tidyverse)
library(ggtree)
library(ggtreeExtra)
library(stringr)
library(gridExtra)
library(grid)
library(ggtext)
# Set complimentary color palettes for host-of-origin and clade affinities
hostcolors <- c(
"steelblue1",
"mediumpurple4",
"darkorange1",
"green4",
"mediumpurple1",
"lightsalmon",
"#E31A1C",
"#20B2AA",
"orchid",
"olivedrab3",
"darkolivegreen",
"lightgray"
)
names(hostcolors) <- scan(text = "P.brutia P.echinata P.elliottii P.nigra P.palustris P.ponderosa P.radiata P.strobus P.sylvestris P.taeda P.thunbergii Unknown", what = "")
cladecolors <- c(
"#20B2AA",
"royalblue",
"firebrick2",
"mediumpurple1",
"goldenrod4",
"darkolivegreen",
"olivedrab3",
"palegreen",
"darkorange1",
"mediumpurple1",
"mediumpurple4",
"purple4",
"azure4",
"#005F5F",
"deeppink1",
"navyblue",
"steelblue1",
"orchid1",
"royalblue",
"palevioletred",
"rosybrown1",
"maroon"
)
names(cladecolors) <- scan(text = "N.USA SpainN SpainS S.USA", what = "")
# Read in tree data
Tree1 <- read.tree("RAxML_bipartitions.LaJul9")
Tree1 <- root(Tree1, outgroup = "CBS133791")
# Read in metadata
tipdata <- read.table("LaAllTreeStrains.txt")
colnames(tipdata) <- c("strain", "cladeID", "hostID")
tipdata$strain = factor(tipdata$strain)
tipdata$hostID <- factor(tipdata$hostID)
tipdata$cladeID <- factor(tipdata$cladeID)
# create genus labels
genusLabels <- paste0("*", names(hostcolors), "*")
# generate metadata for fruit
fruitdata <- tipdata
fruitdata$clade <- fruitdata$cladeID
# Plot the tree
p1 <- ggtree(Tree1, layout = "rectangular")
p2 <- p1 %<+% tipdata +
geom_tiplab(aes(color = hostID), size = 3, align = T, line.size = 0.25, offset = 0.08, show.legend = F) +
geom_nodepoint(aes(label=label, subset = !is.na(as.numeric(label)) & as.numeric(label) ==100), size = 1.5, show.legend=F) +
geom_tippoint(aes(color = hostID), stroke = 0, alpha=0.6, size = 3, position = position_nudge(x = 0.01)) +
scale_color_manual(values=hostcolors,
name ="Host Genus",
labels = genusLabels,
guide=guide_legend(keywidth=0.8,
keyheight=0.8,
ncol=1,
order=2,
override.aes=list(size=4,alpha=0.6)))
p3 <- p2 +
geom_fruit(data=fruitdata, geom=geom_tile, mapping = aes(y=strain, fill=clade), width = 0.06, offset = 0.3, alpha = 0.6) +
scale_fill_manual(values=cladecolors,
name = "Clade ID",
na.translate = F,
guide=guide_legend(keywidth=0.7,
keyheight=0.4,
ncol=1,
order=1
)) +
geom_treescale(x = 0, y = -5, width = 0.1, color = "black", linesize = 0.7, fontsize = 0) +
annotate("text", x = 0.05, y = -3.8, label = "0.1", size = 5) +
theme(plot.margin = unit(c(0.5, 0, 0.5, 0), "cm"),
legend.position = "right",
legend.box = "vertical",
legend.direction = "vertical",
legend.box.margin = margin(t = 0, r = 0, b = 0, l = 0.5),
legend.spacing.y = unit(18, "cm"),
# legend.margin = margin(r = 20, l = -10),
title = element_text(size = rel(1.5)),
legend.text = element_markdown(size = rel(1)),
legend.key.size = unit(0.8, "cm"))
pdf("LaAllTreeNUSArooted.pdf", 8.5, 11)
print(p3)
dev.off()