-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGEBV_pheno_corr.R
209 lines (199 loc) · 7.2 KB
/
GEBV_pheno_corr.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#load packages
#Import effect sizes - Supplementary Data 2
es_file <- read.csv("effect_sizes.csv")
es <- with(es_file, EES.MIA - EES.MAA)
#Import csv files with data on the GEBV sites and unlinked sites
#- Supplementary Data 3
gebv_sites <- read.csv(file = "gebv_sites.csv")
#Extract the genotype matrices
GTAgebv <- gebv_sites[gebv_sites$Age=="Adult", 4:ncol(gebv_sites)]
GTJgebv <- gebv_sites[gebv_sites$Age=="Juv", 4:ncol(gebv_sites)]
#Calculate GEBV scores
new_gebv <- (as.matrix(gebv_sites[,-(1:3)])%*%es) + 1
# Load in phenotype data
gebv_and_ph <- read.csv("phenotypes.csv")
gebv_and_ph_j <- gebv_and_ph[which(gebv_and_ph$Type == "Juvenile"), ]
gebv_and_ph_a <- gebv_and_ph[which(gebv_and_ph$Type == "Adult"), ]
#
qnorm(gebv_and_ph_j$GEBV)
qqline(gebv_and_ph_j$GEBV)
qqnorm(gebv_and_ph_a$GEBV)
qqline(gebv_and_ph_a$GEBV)
#
qqnorm(gebv_and_ph_j$GEBV[which(gebv_and_ph_j$Height > 0.5)])
qqline(gebv_and_ph_j$GEBV[which(gebv_and_ph_j$Height > 0.5)])
# ```
#
```{r}
wilcox.test(gebv_and_ph_a$GEBV, gebv_and_ph_j$GEBV)
t.test(gebv_and_ph_a$GEBV, gebv_and_ph_j$GEBV)
mean(gebv_and_ph_j$GEBV)
mean(gebv_and_ph_a$GEBV)
```
```{r}
t.test(gebv_and_ph_a$GEBV, gebv_and_ph_j$GEBV[which(gebv_and_ph_j$Height < 0.5)])
wilcox.test(gebv_and_ph_a$GEBV, gebv_and_ph_j$GEBV[which(gebv_and_ph_j$Height < 0.5)])
t.test(gebv_and_ph_a$GEBV, gebv_and_ph_j$GEBV[which(gebv_and_ph_j$Height >= 0.5)])
wilcox.test(gebv_and_ph_a$GEBV, gebv_and_ph_j$GEBV[which(gebv_and_ph_j$Height >= 0.5)])
t.test(gebv_and_ph_j$GEBV[which(gebv_and_ph_j$Height >= 0.5)], gebv_and_ph_j$GEBV[which(gebv_and_ph_j$Height < 0.5)])
```
#
#
# Shape data for boxplots
# ```{r}
# h_cutoff <- 0.5
#
# gebv_and_ph_j1 <-
# gebv_and_ph_j[which(gebv_and_ph_j$Height..m. < h_cutoff), ]
# gebv_and_ph_j2 <-
# gebv_and_ph_j[which(gebv_and_ph_j$Height..m. >= h_cutoff), ]
# gebv_for_plots <-
# data.frame(
# c(
# rep("Adults (n = 133)", nrow(gebv_and_ph_a)),
# rep("Juveniles (n = 442)", nrow(gebv_and_ph_j))
# #rep("Juveniles < 0.5m (n = 136)", nrow(gebv_and_ph_j1)),
# #rep("Juveniles >= 0.5m (n = 291)", nrow(gebv_and_ph_j2))
# ),
# c(
# gebv_and_ph_a$GEBV,
# gebv_and_ph_j$GEBV
# #gebv_and_ph_j1$GEBV,
# #gebv_and_ph_j2$GEBV
# )
# )
# colnames(gebv_for_plots) <- c("Cohort", "GEBV")
# ```
# ```{r}
# gebv_boxplot <- ggplot(gebv_for_plots, aes(x = Cohort, y = GEBV)) +
# geom_boxplot(fill = c("#D55E00", "skyblue")) +
# theme_minimal() + xlab("") +
# theme(axis.text=element_text(size=12))
#
# gebv_boxplot
# ```
#
# Plot Score by location
#
# ```{r}
# library(ggpubr)
#
# adult_loc_2019 <- ggplot(data = gebv_and_ph_a, aes(x = Long, y = Lat, size = DBH, colour = PercentScore_2019))+
# geom_point(show.legend = FALSE) +
# theme_minimal() +
# theme(legend.position="bottom", legend.box = "vertical") +
# scale_color_gradient(low = "red", high = "orange") +
# labs(colour = "% Canopy Cover", size = "DBH (cm)") +
# xlab("Longitude") +
# ylab("Latitude") +
# ylim(51.27117, 51.27011) +
# xlim(-0.04020264, -0.038833) +
# guides(colour = guide_colourbar(order = 1),
# size = guide_legend(order = 2))
#
# juv_loc_2019 <- ggplot(data = gebv_and_ph_j, aes(x = Long, y = Lat, size = Height, colour = Score_2019))+
# geom_point(show.legend = FALSE) +
# theme_minimal() +
# theme(legend.position="bottom", legend.box = "vertical") +
# labs(colour = "Health Score", size = "Height (m)") +
# xlab("Longitude") +
# ylab("Latitude") +
# ylim(51.27117, 51.27011) +
# xlim(-0.04020264, -0.038833) +
# guides(colour = guide_colourbar(order = 1),
# size = guide_legend(order = 2))
#
# adult_loc_2021 <- ggplot(data = gebv_and_ph_a, aes(x = Long, y = Lat, size = DBH, colour = PercentScore_2021))+
# geom_point(xlab="GEBV") +
# theme_minimal() +
# theme(legend.position="bottom", legend.box = "vertical") +
# scale_color_gradient(low = "red", high = "orange") +
# labs(colour = "% Canopy Cover", size = "DBH (cm)") +
# xlab("Longitude") +
# ylab("Latitude") +
# ylim(51.27117, 51.27011) +
# xlim(-0.04020264, -0.038833) +
# guides(colour = guide_colourbar(order = 1),
# size = guide_legend(order = 2))
#
# juv_loc_2021 <- ggplot(data = gebv_and_ph_j, aes(x = Long, y = Lat, size = Height, colour = Score_2021))+
# geom_point() +
# theme_minimal() +
# theme(legend.position="bottom", legend.box = "vertical") +
# labs(colour = "Health Score", size = "Height (m)") +
# xlab("Longitude") +
# ylab("Latitude") +
# ylim(51.27117, 51.27011) +
# xlim(-0.04020264, -0.038833) +
# guides(colour = guide_colourbar(order = 1),
# size = guide_legend(order = 2))
#
# ```
# ```{r}
# ggarrange(adult_loc_2019, juv_loc_2019, adult_loc_2021, juv_loc_2021,
# labels = c("Adults : 2019", "Juveniles : 2019", "Adults : 2021", "Juveniles : 2021"),
# ncol = 2, nrow = 2,
# heights = c(1.5, 2.2))
# ```
# ```{r}
adult_loc <- ggplot(data = gebv_and_ph_a, aes(x = Long, y = Lat, size = DBH, colour = GEBV))+
geom_point(xlab="GEBV") +
theme_minimal() +
theme(legend.position="bottom", legend.box = "vertical") +
scale_color_gradient(low = "#fee6ce", high = "#e63f0d") +
labs(colour = "GEBV", size = "DBH (cm)") +
ylim(51.27117, 51.27011) +
xlim(-0.04020264, -0.038833) +
guides(colour = guide_colourbar(order = 1),
size = guide_legend(order = 2))
juv_loc <- ggplot(data = gebv_and_ph_j, aes(x = Long, y = Lat, size = Height, colour = GEBV))+
geom_point() +
theme_minimal() +
theme(legend.position="bottom", legend.box = "vertical") +
labs(colour = "GEBV", size = "Height (m)") +
ylim(51.27117, 51.27011) +
xlim(-0.04020264, -0.038833) +
guides(colour = guide_colourbar(order = 1),
size = guide_legend(order = 2))
ggarrange(adult_loc, juv_loc,
labels = c("Adults", "Juveniles"),
ncol = 2, nrow = 1)
# ```
#
# Exclude the children of tree 51
# ```{r}
children_of_51 <- related$id[which(related$dam == "S51R" | related$sire == "S51R")]
not_51_a <- gebv_and_ph_a[!which(gebv_and_ph_a$Label %in% children_of_51 & gebv_and_ph_a$Label != "S51R"),]
not_51_j <- gebv_and_ph_j[!which(gebv_and_ph_j$Label %in% children_of_51),]
wilcox.test(gebv_and_ph_a$GEBV, gebv_and_ph_j$GEBV)
t.test(gebv_and_ph_a$GEBV, gebv_and_ph_j$GEBV)
# ```
#
# ```{r}
juv_gebv <- ggplot(data = gebv_and_ph_j, aes(x = GEBV-1, y = Score_2019, group = Score_2019))+
geom_violin(fill="skyblue")+
theme_minimal()+
ylab(label = "Health Score")+
xlab("GEBV")
adult_gebv <- ggplot(data = gebv_and_ph_a, aes(x = GEBV-1, y = PercentScore_2019))+
geom_point()+
theme_minimal()+
ylab(label = "Canopy Cover (%)")+
xlab("GEBV")
fig2 <- ggarrange(adult_gebv, juv_gebv,
labels = c("Adults", "Juveniles"),
ncol = 2, nrow = 1)+
xlab("GEBV")
fig2
```
```{r}
tiff("/Users/carey/University/Marden_Park/Figures/Final_Figures/mp_ex_data_fig3.tiff", units="mm", width=180, height=100, res=300)
fig2
dev.off()
png("/Users/carey/University/Marden_Park/Figures/Final_Figures/mp_ex_data_fig3.png", units="mm", width=180, height=100, res=300)
fig2
dev.off()
jpeg("/Users/carey/University/Marden_Park/Figures/Final_Figures/mp_ex_data_fig3.jpeg", units="mm", width=180, height=100, res=300)
fig2
dev.off()
```