-
Notifications
You must be signed in to change notification settings - Fork 2
/
.Rhistory
512 lines (512 loc) · 26.5 KB
/
.Rhistory
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
dev.off()
#Load libraries
library(dplyr)
library(tidyr)
library(ggplot2)
theme_set(theme_bw())
#Load in data
load("R-scripts/Rdata/tidy_df_ideal_twopop.Rdata")
#Making sure the data is in the correct format
tidy_df$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df$maternal_trees = as.numeric(tidy_df$maternal_trees)
#Load in data
load("R-scripts/Rdata/tidy_df_ideal_twopop.Rdata")
#Making sure the data is in the correct format
tidy_df$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df$maternal_trees = as.numeric(tidy_df$maternal_trees)
Histogram of total alleles simulated for all simulation replicates to get an idea of the variation across replicates
ggplot(tidy_df, aes(x=as.numeric(total_alleles))) +
geom_bar() +
ggtitle("Variation of total alleles simulated across replicates") +
theme(axis.text.y=element_blank(),
axis.ticks.y=element_blank())
#defining a color palette to use for the plots (color-blind accessible)
cbPalette <- c("#E69F00", "#56B4E9", "#CC79A7")
#defining more descriptive labels for the facets
mat_tree_labs = c("1 maternal tree", "2 maternal trees", "5 maternal trees", "10 maternal trees", "25 maternal trees", "50 maternal trees", "100 maternal trees")
names(mat_tree_labs) = c("1", "2", "5", "10", "25", "50", "100")
#defining more descriptive labels for the facets
mat_tree_labs = c("1 maternal plant", "2 maternal plants", "5 maternal plants", "10 maternal plants", "25 maternal plants", "50 maternal plants", "100 maternal plants")
names(mat_tree_labs) = c("1", "2", "5", "10", "25", "50", "100")
tidy_df %>%
ggplot(aes(x=as.numeric(total_seeds), y=as.numeric(prop_capt), color=donor_type)) +
geom_point() +
facet_wrap(vars(as.numeric(maternal_trees)), labeller = labeller(maternal_trees = mat_tree_labs)) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
ylim(0,1) +
ggtitle("Genetic diversity capture across all ideal sampling scenarios") +
ylab("Proportion of alleles captured") +
xlab("Total seeds sampled") +
scale_colour_manual(values=cbPalette, labels = c("All eligible", "All same", "Skewed")) +
labs(color = "Donor Type")
#Load in data
load("Rdata/tidy_df_realistic_twopop.Rdata")
tidy_df_realistic = tidy_df
#Making sure the data is in the correct format
tidy_df_realistic$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df_realistic$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df_realistic$maternal_trees = as.numeric(tidy_df$maternal_trees)
load("Rdata/tidy_df_ideal_twopop.Rdata")
load("R-scripts/Rdata/tidy_df_ideal_twopop.Rdata")
#Making sure the data is in the correct format
tidy_df$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df$maternal_trees = as.numeric(tidy_df$maternal_trees)
#remove col to make same # cols
#tidy_df = subset(tidy_df, select = -c(seeds_per_tree))
#Create new columns to identify scenarios
tidy_df$samp_type = "ideal"
tidy_df_realistic$samp_type = "realistic"
#Combine dataframes
combined_ideal_real = rbind(tidy_df, tidy_df_realistic)
#Make sure variables are in the correct format
combined_ideal_real$donor_type = factor(combined_ideal_real$donor_type)
combined_ideal_real$samp_type = factor(combined_ideal_real$samp_type)
combined_ideal_real$prop_capt = as.numeric(combined_ideal_real$prop_capt)
combined_ideal_real$maternal_trees = as.numeric(combined_ideal_real$maternal_trees)
#defining more descriptive labels for the facets
mat_tree_labs = c("2 maternal plants", "5 maternal plants", "10 maternal plants", "25 maternal plants", "50 maternal plants", "100 maternal plants")
names(mat_tree_labs) = c("2", "5", "10", "25", "50", "100")
#defining a color palette to use for the plots (color-blind accessible)
cbPalette <- c("#E69F00", "#f5d58e", "#56B4E9", "#96daf2", "#CC79A7", "#fcd2e9")
#Plotting the data
combined_ideal_real %>%
filter(total_seeds==200) %>%
filter(as.numeric(maternal_trees)>1) %>%
ggplot() +
geom_boxplot(aes(x=donor_type, y=as.numeric(prop_capt), color=interaction(samp_type, donor_type))) +
facet_wrap(vars(maternal_trees), labeller = labeller(maternal_trees = mat_tree_labs)) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
ylim(0.3,1) +
ggtitle("Genetic diversity capture for scenarios with 400 total seeds sampled") +
xlab("Donor type") +
ylab("Proportion of alleles captured") +
labs(color = "Sampling Type") +
scale_x_discrete(labels=c("Eligible","Same","Skewed")) +
scale_colour_manual(values=cbPalette, labels = c("Eligible ideal", "Eligible realistic", "Same ideal", "Same realistic", "Skewed ideal", "Skewed realistic"))
#Plotting the data
combined_ideal_real %>%
filter(total_seeds==400) %>%
filter(as.numeric(maternal_trees)>1) %>%
ggplot() +
geom_boxplot(aes(x=donor_type, y=as.numeric(prop_capt), color=interaction(samp_type, donor_type))) +
facet_wrap(vars(maternal_trees), labeller = labeller(maternal_trees = mat_tree_labs)) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
ylim(0.3,1) +
ggtitle("Genetic diversity capture for scenarios with 400 total seeds sampled") +
xlab("Donor type") +
ylab("Proportion of alleles captured") +
labs(color = "Sampling Type") +
scale_x_discrete(labels=c("Eligible","Same","Skewed")) +
scale_colour_manual(values=cbPalette, labels = c("Eligible ideal", "Eligible realistic", "Same ideal", "Same realistic", "Skewed ideal", "Skewed realistic"))
#Plotting the data
combined_ideal_real %>%
filter(total_seeds==200) %>%
filter(as.numeric(maternal_trees)>1) %>%
ggplot() +
geom_boxplot(aes(x=donor_type, y=as.numeric(prop_capt), color=interaction(samp_type, donor_type))) +
facet_wrap(vars(maternal_trees), labeller = labeller(maternal_trees = mat_tree_labs)) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
ylim(0.3,1) +
ggtitle("Genetic diversity capture for scenarios with 400 total seeds sampled") +
xlab("Donor type") +
ylab("Proportion of alleles captured") +
labs(color = "Sampling Type") +
scale_x_discrete(labels=c("Eligible","Same","Skewed")) +
scale_colour_manual(values=cbPalette, labels = c("Panmictic ideal", "Panmictic realistic", "Highly limited ideal", "Highly limited realistic", "Limited ideal", "Limited realistic"))
pdf("FigureS6.pdf, height = 7, width = 8")
#Plotting the data
combined_ideal_real %>%
filter(total_seeds==200) %>%
filter(as.numeric(maternal_trees)>1) %>%
ggplot() +
geom_boxplot(aes(x=donor_type, y=as.numeric(prop_capt), color=interaction(samp_type, donor_type))) +
facet_wrap(vars(maternal_trees), labeller = labeller(maternal_trees = mat_tree_labs)) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
ylim(0.3,1) +
ggtitle("Genetic diversity capture for scenarios with 400 total seeds sampled") +
xlab("Donor type") +
ylab("Proportion of alleles captured") +
labs(color = "Sampling Type") +
scale_x_discrete(labels=c("Eligible","Same","Skewed")) +
scale_colour_manual(values=cbPalette, labels = c("Panmictic ideal", "Panmictic realistic", "Highly limited ideal", "Highly limited realistic", "Limited ideal", "Limited realistic"))
dev.off()
pdf("FigureS6.pdf", height = 7, width = 8")
#Plotting the data
combined_ideal_real %>%
filter(total_seeds==200) %>%
filter(as.numeric(maternal_trees)>1) %>%
pdf("FigureS6.pdf", height = 7, width = 8)
#Plotting the data
combined_ideal_real %>%
filter(total_seeds==200) %>%
filter(as.numeric(maternal_trees)>1) %>%
ggplot() +
geom_boxplot(aes(x=donor_type, y=as.numeric(prop_capt), color=interaction(samp_type, donor_type))) +
facet_wrap(vars(maternal_trees), labeller = labeller(maternal_trees = mat_tree_labs)) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
ylim(0.3,1) +
ggtitle("Genetic diversity capture for scenarios with 400 total seeds sampled") +
xlab("Donor type") +
ylab("Proportion of alleles captured") +
labs(color = "Sampling Type") +
scale_x_discrete(labels=c("Eligible","Same","Skewed")) +
scale_colour_manual(values=cbPalette, labels = c("Panmictic ideal", "Panmictic realistic", "Highly limited ideal", "Highly limited realistic", "Limited ideal", "Limited realistic"))
dev.off()
#Plotting the data
combined_ideal_real %>%
filter(total_seeds==200) %>%
filter(as.numeric(maternal_trees)>1) %>%
ggplot() +
geom_boxplot(aes(x=donor_type, y=as.numeric(prop_capt), color=interaction(samp_type, donor_type))) +
facet_wrap(vars(maternal_trees), labeller = labeller(maternal_trees = mat_tree_labs)) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
ylim(0.3,1) +
ggtitle("Genetic diversity capture for scenarios with 400 total seeds sampled") +
xlab("Donor type") +
ylab("Proportion of alleles captured") +
labs(color = "Sampling Type") +
scale_x_discrete(labels=c("Eligible","Same","Skewed")) +
scale_colour_manual(values=cbPalette, labels = c("Panmictic ideal", "Panmictic realistic", "Highly limited ideal", "Highly limited realistic", "Limited ideal", "Limited realistic"))
#Load in data
load("Rdata/tidy_df_realistic_twopop.Rdata")
tidy_df_realistic = tidy_df
#Making sure the data is in the correct format
tidy_df_realistic$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df_realistic$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df_realistic$maternal_trees = as.numeric(tidy_df$maternal_trees)
load("R-scripts/Rdata/tidy_df_ideal_twopop.Rdata")
#Making sure the data is in the correct format
tidy_df$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df$maternal_trees = as.numeric(tidy_df$maternal_trees)
#remove col to make same # cols
#tidy_df = subset(tidy_df, select = -c(seeds_per_tree))
#Create new columns to identify scenarios
tidy_df$samp_type = "ideal"
tidy_df_realistic$samp_type = "realistic"
#Combine dataframes
combined_ideal_real = rbind(tidy_df, tidy_df_realistic)
#Make sure variables are in the correct format
combined_ideal_real$donor_type = factor(combined_ideal_real$donor_type)
combined_ideal_real$samp_type = factor(combined_ideal_real$samp_type)
combined_ideal_real$prop_capt = as.numeric(combined_ideal_real$prop_capt)
combined_ideal_real$maternal_trees = as.numeric(combined_ideal_real$maternal_trees)
#defining more descriptive labels for the facets
mat_tree_labs = c("2 maternal plants", "5 maternal plants", "10 maternal plants", "25 maternal plants", "50 maternal plants", "100 maternal plants")
names(mat_tree_labs) = c("2", "5", "10", "25", "50", "100")
#defining a color palette to use for the plots (color-blind accessible)
cbPalette <- c("#E69F00", "#f5d58e", "#56B4E9", "#96daf2", "#CC79A7", "#fcd2e9")
pdf("FigureS6.pdf", height = 7, width = 8)
#Plotting the data
combined_ideal_real %>%
filter(total_seeds==200) %>%
filter(as.numeric(maternal_trees)>1) %>%
ggplot() +
geom_boxplot(aes(x=donor_type, y=as.numeric(prop_capt), color=interaction(samp_type, donor_type))) +
facet_wrap(vars(maternal_trees), labeller = labeller(maternal_trees = mat_tree_labs)) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
ylim(0.3,1) +
ggtitle("Genetic diversity capture for scenarios with 400 total seeds sampled") +
xlab("Donor type") +
ylab("Proportion of alleles captured") +
labs(color = "Sampling Type") +
scale_x_discrete(labels=c("Eligible","Same","Skewed")) +
scale_colour_manual(values=cbPalette, labels = c("Panmictic ideal", "Panmictic realistic", "Highly limited ideal", "Highly limited realistic", "Limited ideal", "Limited realistic"))
pdf("FigureS6.pdf", height = 7, width = 8)
#Plotting the data
combined_ideal_real %>%
filter(total_seeds==200) %>%
filter(as.numeric(maternal_trees)>1) %>%
ggplot() +
geom_boxplot(aes(x=donor_type, y=as.numeric(prop_capt), color=interaction(samp_type, donor_type))) +
facet_wrap(vars(maternal_trees), labeller = labeller(maternal_trees = mat_tree_labs)) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
ylim(0.3,1) +
ggtitle("Genetic diversity capture for scenarios with 400 total seeds sampled") +
xlab("Donor type") +
ylab("Proportion of alleles captured") +
labs(color = "Sampling Type") +
scale_x_discrete(labels=c("Eligible","Same","Skewed")) +
scale_colour_manual(values=cbPalette, labels = c("Panmictic ideal", "Panmictic realistic", "Highly limited ideal", "Highly limited realistic", "Limited ideal", "Limited realistic"))
dev.off()
getwd()
#Load libraries
library(dplyr)
library(tidyr)
library(ggplot2)
theme_set(theme_bw())
#Load in data
load("R-scripts/Rdata/tidy_df_ideal.Rdata")
#Making sure the data is in the correct format
tidy_df$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df$maternal_trees = as.numeric(tidy_df$maternal_trees)
#Load in data
load("Rdata/tidy_df_realistic.Rdata")
tidy_df_realistic = tidy_df
#Making sure the data is in the correct format
tidy_df_realistic$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df_realistic$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df_realistic$maternal_trees = as.numeric(tidy_df$maternal_trees)
load("R-scripts/Rdata/tidy_df_ideal.Rdata")
#Making sure the data is in the correct format
tidy_df$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df$maternal_trees = as.numeric(tidy_df$maternal_trees)
#remove col to make same # cols
#tidy_df_realistic = subset(tidy_df, select = -c(seeds_per_tree))
#Create new columns to identify scenarios
tidy_df$samp_type = "ideal"
tidy_df_realistic$samp_type = "realistic"
#Combine dataframes
combined_ideal_real = rbind(tidy_df, tidy_df_realistic)
#Make sure variables are in the correct format
combined_ideal_real$donor_type = factor(combined_ideal_real$donor_type)
combined_ideal_real$samp_type = factor(combined_ideal_real$samp_type)
combined_ideal_real$prop_capt = as.numeric(combined_ideal_real$prop_capt)
combined_ideal_real$maternal_trees = as.numeric(combined_ideal_real$maternal_trees)
#defining more descriptive labels for the facets
mat_tree_labs = c("2 maternal plants", "5 maternal plants", "10 maternal plants", "25 maternal plants", "50 maternal plants", "100 maternal plants")
names(mat_tree_labs) = c("2", "5", "10", "25", "50", "100")
#defining a color palette to use for the plots (color-blind accessible)
cbPalette <- c("#E69F00", "#f5d58e", "#56B4E9", "#96daf2", "#CC79A7", "#fcd2e9")
pdf("Figure4.pdf", height = 7, width = 8)
#Plotting the data
combined_ideal_real %>%
filter(total_seeds==200) %>%
filter(as.numeric(maternal_trees)>1) %>%
ggplot() +
geom_boxplot(aes(x=donor_type, y=as.numeric(prop_capt), color=interaction(samp_type, donor_type))) +
facet_wrap(vars(maternal_trees), labeller = labeller(maternal_trees = mat_tree_labs)) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
ylim(0.3,1) +
ggtitle("Ex situ genetic diversity representation for scenarios with 200 total seeds sampled") +
xlab("Donor type") +
ylab("Proportion of alleles captured") +
labs(color = "Sampling Type") +
scale_x_discrete(labels=c("Eligible","Same","Skewed")) +
scale_colour_manual(values=cbPalette, labels = c("Panmictic ideal", "Panmictic realistic", "Highly limited ideal", "Highly limited realistic", "Limited ideal", "Limited realistic"))
dev.off()
#Load libraries
library(dplyr)
library(tidyr)
library(ggplot2)
theme_set(theme_bw())
#Load in data
load("R-scripts/Rdata/tidy_df_ideal.Rdata")
#Making sure the data is in the correct format
tidy_df$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df$maternal_trees = as.numeric(tidy_df$maternal_trees)
#Load in data
load("R-scripts/Rdata/tidy_df_ideal.Rdata")
#Making sure the data is in the correct format
tidy_df$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df$maternal_trees = as.numeric(tidy_df$maternal_trees)
Histogram of total alleles simulated for all simulation replicates to get an idea of the variation across replicates
**Ideal Scenarios**
Scatter plot of all raw data obtained from resampling. Plots are faceted by maternal trees, and each color line represents a different pollen donor type.
#defining more descriptive labels for the facets
mat_tree_labs = c("1", "2", "5", "10", "25", "50", "100")
names(mat_tree_labs) = c("1 maternal plant", "2 maternal plants", "5 maternal plants", "10 maternal plants", "25 maternal plants", "50 maternal plants", "100 maternal plants")
#Load in data
load("Rdata/tidy_df_realistic.Rdata")
tidy_df_realistic = tidy_df
#Load in data
load("R-scripts/Rdata/tidy_df_realistic.Rdata")
tidy_df_realistic = tidy_df
#Making sure the data is in the correct format
tidy_df_realistic$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df_realistic$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df_realistic$maternal_trees = as.numeric(tidy_df$maternal_trees)
#defining a color palette to use for the plots (color-blind accessible)
cbPalette <- c("#E69F00", "#56B4E9", "#CC79A7")
#defining more descriptive labels for the facets
mat_tree_labs = c("1 maternal plant", "2 maternal plants", "5 maternal plants", "10 maternal plants", "25 maternal plants", "50 maternal plants", "100 maternal plants")
load("R-scripts/Rdata/tidy_df_ideal.Rdata")
#Making sure the data is in the correct format
tidy_df$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df$maternal_trees = as.numeric(tidy_df$maternal_trees)
#remove col to make same # cols
#tidy_df_realistic = subset(tidy_df, select = -c(seeds_per_tree))
#Create new columns to identify scenarios
tidy_df$samp_type = "ideal"
tidy_df_realistic$samp_type = "realistic"
#Combine dataframes
combined_ideal_real = rbind(tidy_df, tidy_df_realistic)
#remove col to make same # cols
tidy_df_realistic = subset(tidy_df, select = -c(seeds_per_tree))
#Create new columns to identify scenarios
tidy_df$samp_type = "ideal"
tidy_df_realistic$samp_type = "realistic"
#Combine dataframes
combined_ideal_real = rbind(tidy_df, tidy_df_realistic)
#Load in data
load("R-scripts/Rdata/tidy_df_realistic.Rdata")
tidy_df_realistic = tidy_df
#Making sure the data is in the correct format
tidy_df_realistic$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df_realistic$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df_realistic$maternal_trees = as.numeric(tidy_df$maternal_trees)
load("R-scripts/Rdata/tidy_df_ideal.Rdata")
#Making sure the data is in the correct format
tidy_df$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df$maternal_trees = as.numeric(tidy_df$maternal_trees)
#remove col to make same # cols
#tidy_df_realistic = subset(tidy_df, select = -c(seeds_per_tree))
#Create new columns to identify scenarios
tidy_df$samp_type = "ideal"
tidy_df_realistic$samp_type = "realistic"
ncol(tidy_df)
ncol(tidy_df_realistic)
colnames(tidy_df)
colnames(tidy_df_realistic)
#remove col to make same # cols
tidy_df = subset(tidy_df, select = -c(seeds_per_tree))
#Create new columns to identify scenarios
tidy_df$samp_type = "ideal"
tidy_df_realistic$samp_type = "realistic"
#Combine dataframes
combined_ideal_real = rbind(tidy_df, tidy_df_realistic)
#Make sure variables are in the correct format
combined_ideal_real$donor_type = factor(combined_ideal_real$donor_type)
combined_ideal_real$samp_type = factor(combined_ideal_real$samp_type)
combined_ideal_real$prop_capt = as.numeric(combined_ideal_real$prop_capt)
combined_ideal_real$maternal_trees = as.numeric(combined_ideal_real$maternal_trees)
#defining more descriptive labels for the facets
mat_tree_labs = c("2 maternal plants", "5 maternal plants", "10 maternal plants", "25 maternal plants", "50 maternal plants", "100 maternal plants")
names(mat_tree_labs) = c("2", "5", "10", "25", "50", "100")
#defining a color palette to use for the plots (color-blind accessible)
cbPalette <- c("#E69F00", "#f5d58e", "#56B4E9", "#96daf2", "#CC79A7", "#fcd2e9")
pdf("Figure4.pdf", height = 7, width = 8)
pdf("FigureS2.pdf", height = 7, width = 8)
#Plotting the data
combined_ideal_real %>%
filter(total_seeds==400) %>%
filter(as.numeric(maternal_trees)>1) %>%
ggplot() +
geom_boxplot(aes(x=donor_type, y=as.numeric(prop_capt), color=interaction(samp_type, donor_type))) +
facet_wrap(vars(maternal_trees), labeller = labeller(maternal_trees = mat_tree_labs)) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
ylim(0.3,1) +
ggtitle("Ex situ genetic diversity representation for scenarios with 200 total seeds sampled") +
xlab("Donor type") +
ylab("Proportion of alleles captured") +
labs(color = "Sampling Type") +
scale_x_discrete(labels=c("Eligible","Same","Skewed")) +
scale_colour_manual(values=cbPalette, labels = c("Panmictic ideal", "Panmictic realistic", "Highly limited ideal", "Highly limited realistic", "Limited ideal", "Limited realistic"))
dev.off()
#Load libraries required for the whole script
library(dplyr)
library(tidyr)
library(ggplot2)
theme_set(theme_bw())
#Load in data
#load("R-scripts/Rdata/tidy_df_ideal.Rdata")
#Two pop data:
load("R-scripts/Rdata/tidy_df_ideal_twopop.Rdata")
#Converting these to numeric--they already should be, but they must have been converted accidentally when making the matrix a dataframe, etc...
tidy_df$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df$maternal_trees = as.numeric(tidy_df$maternal_trees)
#Subset the data by maternal tree to run two separate models
sub_1 = tidy_df %>% subset(maternal_trees < 25)
sub_2 = tidy_df %>% subset(maternal_trees >= 25)
#Running the models
model_1 = lm(prop_capt ~ log(total_seeds) * log(maternal_trees) * donor_type, data = sub_1)
model_2 = lm(prop_capt ~ total_seeds * maternal_trees * donor_type, data = sub_2)
#Creating a new dataframe of values to base predictions on
newd_1 = data.frame(maternal_trees=(rep(c(1,2,5,10), each=1500)), total_seeds=rep(seq(1,500,1),12), donor_type=factor(rep((rep(c("all_eligible", "all_same", "skewed"), each=500)), 4)))
#Predictions
pmu_1 = predict(model_1, re.form=NA, transform = TRUE, newdata=newd_1)
newd_2 = data.frame(maternal_trees=(rep(c(25,50,100), each=1500)), total_seeds=rep(seq(1,500,1),9), donor_type=factor(rep((rep(c("all_eligible", "all_same", "skewed"), each=500)), 3)))
#Predictions
pmu_2 = predict(model_2, re.form=NA, transform = TRUE, newdata=newd_2)
#Creating a dataframe to plot in ggplot
preds_1 <- cbind(newd_1, pmu_1)
colnames(preds_1) = c("maternal_trees", "total_seeds", "donor_type", "pmu")
preds_2 <- cbind(newd_2, pmu_2)
colnames(preds_2) = c("maternal_trees", "total_seeds", "donor_type", "pmu")
preds = rbind(preds_1, preds_2)
#defining a color palette to use for the plots (color-blind accessible)
cbPalette <- c("#E69F00", "#56B4E9", "#CC79A7")
#defining more descriptive labels for the facets
mat_tree_labs = c("1 maternal plant", "2 maternal plants", "5 maternal plants", "10 maternal plants", "25 maternal plants", "50 maternal plants", "100 maternal plants")
names(mat_tree_labs) = c("1", "2", "5", "10", "25", "50", "100")
pdf("FigureS4.pdf", height = 7, width = 8)
#Plotting the data
ggplot(data=preds) +
geom_point(data = tidy_df, aes(x=as.numeric(total_seeds), y=as.numeric(prop_capt), color=donor_type), alpha=0.25) +
facet_wrap(vars(maternal_trees), labeller = labeller(maternal_trees = mat_tree_labs)) +
geom_line(data=preds, mapping = aes(x=(total_seeds), y=pmu, lty=donor_type), show.legend=F) +
ggtitle("Ex situ genetic diversity representation across all ideal sampling scenarios") +
ylab("Proportion of alleles captured") +
xlab("Total seeds sampled") +
scale_colour_manual(values=cbPalette, labels = c("Panmictic", "Highly limited", "Limited")) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
labs(color = "Donor Type")
dev.off()
#Load libraries required for the whole script
library(dplyr)
library(tidyr)
library(ggplot2)
theme_set(theme_bw())
#Load in data
#load("R-scripts/Rdata/tidy_df_realistic.Rdata")
#Two pop data:
load("R-scripts/Rdata/tidy_df_realistic_twopop.Rdata")
#Converting these to numeric--they already should be, but they must have been converted accidentally when making the matrix a dataframe, etc...
tidy_df$prop_capt = as.numeric(tidy_df$prop_capt)
tidy_df$total_seeds = as.numeric(tidy_df$total_seeds)
tidy_df$maternal_trees = as.numeric(tidy_df$maternal_trees)
#Subset the data by maternal tree to run two separate models
sub_1 = tidy_df %>% subset(maternal_trees < 25)
sub_2 = tidy_df %>% subset(maternal_trees >= 25)
#Running the models
model_1 = lm(prop_capt ~ log(total_seeds) * log(maternal_trees) * donor_type, data = sub_1)
model_2 = lm(prop_capt ~ total_seeds * maternal_trees * donor_type, data = sub_2)
# #Save the model since it takes so long to run
#save(transformed_model, file = "transformed_model.Rdata")
#Load the model from previously saved run
#load("transformed_model.Rdata")
#Model summary!
#summary(transformed_model, digits = 4)
```
```{r}
#Creating a new dataframe of values to base predictions on
newd_1 = data.frame(maternal_trees=(rep(c(2,5,10), each=1500)), total_seeds=rep(seq(1,500,1),9), donor_type=factor(rep((rep(c("all_eligible", "all_same", "skewed"), each=500)), 3)))
#Predictions
pmu_1 = predict(model_1, re.form=NA, transform = TRUE, newdata=newd_1)
newd_2 = data.frame(maternal_trees=(rep(c(25,50,100), each=1500)), total_seeds=rep(seq(1,500,1),9), donor_type=factor(rep((rep(c("all_eligible", "all_same", "skewed"), each=500)), 3)))
#Predictions
pmu_2 = predict(model_2, re.form=NA, transform = TRUE, newdata=newd_2)
#Creating a dataframe to plot in ggplot
preds_1 <- cbind(newd_1, pmu_1)
colnames(preds_1) = c("maternal_trees", "total_seeds", "donor_type", "pmu")
preds_2 <- cbind(newd_2, pmu_2)
colnames(preds_2) = c("maternal_trees", "total_seeds", "donor_type", "pmu")
preds = rbind(preds_1, preds_2)
#defining a color palette to use for the plots (color-blind accessible)
cbPalette <- c("#E69F00", "#56B4E9", "#CC79A7")
#defining more descriptive labels for the facets
mat_tree_labs = c("2 maternal plants", "5 maternal plants", "10 maternal plants", "25 maternal plants", "50 maternal plants", "100 maternal plants") #removed 1 maternal tree
names(mat_tree_labs) = c("2", "5", "10", "25", "50", "100") #removed 1
pdf("FigureS5.pdf", height = 7, width = 8)
#Plotting the data
ggplot(data=preds) +
geom_point(data = tidy_df, aes(x=as.numeric(total_seeds), y=as.numeric(prop_capt), color=donor_type), alpha=0.25) +
facet_wrap(vars(maternal_trees), labeller = labeller(maternal_trees = mat_tree_labs)) +
geom_line(data=preds, mapping = aes(x=(total_seeds), y=pmu, lty=donor_type), show.legend=F) +
ggtitle("Ex situ genetic diversity representation across all realistic sampling scenarios") +
ylab("Proportion of alleles captured") +
xlab("Total seeds sampled") +
scale_colour_manual(values=cbPalette, labels = c("Panmictic", "Highly limited", "Limited")) +
theme(strip.background = element_rect(color="black", fill="#F2F2F2", linetype="solid")) +
labs(color = "Donor Type")
dev.off()