This repository has been archived by the owner on May 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.Rhistory
512 lines (512 loc) · 23.1 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
rbind(
dfFrequentNames %>% select(Species),
dfFrequentNames %>% select(SpeciesNew) %>% rename(Species = SpeciesNew)) %>%
unique %>%
arrange(Species) %>%
# filter(SpeciesNew %in% TBMFspp) %>% # Exclude species from Cascadia ecoregions
pull(Species) %>%
paste(collapse = "” OR “") -> BooleanSpp
paste("(seed OR seeds) AND (dormancy OR germination) AND (“", BooleanSpp, "”)", sep ="") %>%
write.table(here("results", "Boolean search string.txt"), row.names = F)
read.csv("../#data/germination/results/TBMF_Database.csv") -> TBMF
read.csv("../#data/germination/results/TBMF_Database.csv") -> TBMFDB
readr::write_excel_csv(TBMFDB, here::here("results", "TBMF_Database.csv"))
readr::write_excel_csv(TBMFDB, here::here("data", "TBMF_Database.csv"))
paste("(seed OR seeds) AND (dormancy OR germination) AND (“", BooleanSpp, "”)", sep ="") %>%
write.table(here("data", "Boolean search string.txt"), row.names = F)
library(tidyverse); library(here); library(sp); library(openxlsx)
# Cleaning of the search string
## TPL Names from common source
read.csv("../#data/tpl/results/TPLNames.csv") -> Names # TPL taxonomy files are in my home drive
read.csv("../#data/tpl/results/Families.csv") -> SeedFamilies # TPL taxonomy files are in my home drive
## Clean species file
rbind(
read.csv("../#data/plots/data/sPlot12/species_Edu.csv") %>% # sPlot vegetation files are in my home drive
select(PlotObservationID, species, Relative.cover) %>%
rename(Cover = Relative.cover, PlotID = PlotObservationID, Taxon = species) %>%
mutate(PlotID = paste("Rest", PlotID, sep = "_")),
read.csv("../#data/plots/data/sPlot12/forest2_1500.csv", sep = "\t") %>% # sPlot vegetation files are in my home drive
select(Relevé.number, Species.name, Cover..) %>%
rename(Cover = Cover.., PlotID = Relevé.number, Taxon = Species.name) %>%
mutate(PlotID = paste("Japan", PlotID, sep = "_"))) %>%
merge(Names, by = "Taxon", all.x = TRUE) %>%
filter(Family %in% SeedFamilies$Family) %>%
select(PlotID, New.ID, Cover) -> dfSpeciesRevised
## Clean plot header file
rbind(
read.csv("../#data/plots/data/sPlot12/TDFNH3_Edu.csv") %>% # sPlot vegetation files are in my home drive
filter(Herbs.identified..y.n. != "N" |
! Plants.recorded %in% c("All trees & dominant shrubs",
"All woody species",
"Dominant woody plants >= 2.5 cm dbh",
"Woody plants >= 2.5 cm dbh")) %>%
select(PlotObservationID, ECO_NAME, Altitude..m., Aspect..Â..,
Slope..Â.., POINT_X, POINT_Y) %>%
rename(PlotID = PlotObservationID,
Ecoregion = ECO_NAME,
Altitude = Altitude..m.,
Aspect = Aspect..Â..,
Slope = Slope..Â..,
Longitude = POINT_X,
Latitude = POINT_Y) %>%
mutate(PlotID = paste("Rest", PlotID, sep = "_")),
read.table("../#data/plots/data/sPlot12/japan2.txt", sep = ";", header = T) %>% # sPlot vegetation files are in my home drive
select(PlotID, REALM:ECO_NAME) %>%
merge(read.csv("../#data/plots/data/sPlot12/forest2_1500.hea", sep = "\t", quote = ""), by = "PlotID") %>% # sPlot vegetation files are in my home drive
filter(BIOME == 4) %>%
select(Relevé.number, ECO_NAME, Altitude..m., Aspect....,
Slope...., DEG_LON, DEG_LAT) %>%
rename(PlotID = Relevé.number,
Ecoregion = ECO_NAME,
Altitude = Altitude..m.,
Aspect = Aspect....,
Slope = Slope....,
Longitude = DEG_LON,
Latitude = DEG_LAT) %>%
mutate(PlotID = paste("Japan", PlotID, sep = "_"),
Longitude = as.numeric(gsub("*,", ".", Longitude)),
Latitude = as.numeric(gsub("*,", ".", Latitude)))) -> dfHeader
## Calculate frequencies, filter out rare species
dfHeader %>%
select(PlotID, Ecoregion) %>%
unique %>%
group_by(Ecoregion) %>%
summarise(T = length(Ecoregion)) -> dfTotals
merge(dfSpeciesRevised, dfHeader, by = "PlotID") %>%
select(PlotID, New.ID, Ecoregion) %>%
unique %>%
group_by(Ecoregion, New.ID) %>%
summarise(N = length(New.ID)) -> dfCounts
merge(dfCounts, dfTotals, by = "Ecoregion") %>%
mutate(F = N/T) %>%
filter(F > 0.05) %>%
pull(New.ID) %>%
unique -> FrequentSpp
Names %>%
filter(New.ID %in% FrequentSpp) %>%
mutate(Species = paste(Genus, Species, sep = " "),
SpeciesNew = paste(New.Genus, New.Species, sep = " ")) %>%
select(New.ID, Species, SpeciesNew) %>%
arrange(Species) -> dfFrequentNames
merge(dfCounts, dfTotals, by = "Ecoregion") %>%
mutate(F = N/T) %>%
filter(! Ecoregion %in% c("Cascade Mountains leeward forests", "Central and Southern Cascades forests",
"Eastern Cascades forests")) %>% # These ecoregions are in the vegetation db, but belong to different biome
filter(F > 0.05) %>%
select(New.ID) %>%
unique %>%
merge(Names) %>%
mutate(Species = paste(Genus, Species, sep = " "),
SpeciesNew = paste(New.Genus, New.Species, sep = " ")) %>%
select(SpeciesNew) %>%
unique %>%
arrange(SpeciesNew) %>%
pull(SpeciesNew) -> TBMFspp
## Create Boolean search string
rbind(
dfFrequentNames %>% select(Species),
dfFrequentNames %>% select(SpeciesNew) %>% rename(Species = SpeciesNew)) %>%
unique %>%
arrange(Species) %>%
# filter(SpeciesNew %in% TBMFspp) %>% # Exclude species from Cascadia ecoregions
pull(Species) %>%
paste(collapse = "” OR “") -> BooleanSpp
paste("(seed OR seeds) AND (dormancy OR germination) AND (“", BooleanSpp, "”)", sep ="") %>%
write.table(here("data", "Boolean search string.txt"), row.names = F)
# Cleaning of the database
read.csv("../#data/germination/results/TBMF_Database.csv") -> TBMFDB
readr::write_excel_csv(TBMFDB, here::here("data", "TBMF_Database.csv"))
# Calculate numbers for the manuscript main text
dfFrequentNames %>%
filter(SpeciesNew %in% TBMFspp) %>%
pull(SpeciesNew) %>% unique %>% length -> MSfrequentspp
merge(dfHeader, dfSpeciesRevised, by = "PlotID") %>%
filter(! Ecoregion %in% c("Cascade Mountains leeward forests", "Central and Southern Cascades forests",
"Eastern Cascades forests")) %>% # These ecoregions are in the vegetation db, but belong to different biome
select(New.ID) %>%
unique %>%
merge(Names, by = "New.ID") %>%
mutate(SpeciesNew = paste(New.Genus, New.Species, sep = " ")) %>%
pull(SpeciesNew) %>% unique %>% length -> MStotalspp
dfHeader %>%
filter(! Ecoregion %in% c("Cascade Mountains leeward forests", "Central and Southern Cascades forests",
"Eastern Cascades forests")) %>% # These ecoregions are in the vegetation db, but belong to different biome
pull(PlotID) %>% unique %>% length -> MSplots
dfHeader %>%
filter(! Ecoregion %in% c("Cascade Mountains leeward forests", "Central and Southern Cascades forests",
"Eastern Cascades forests")) %>% # These ecoregions are in the vegetation db, but belong to different biome
pull(Ecoregion) %>% unique %>% length -> MSecoregions
TBMFDB %>% tally() -> MSrecords
TBMFDB %>% pull(Reference) %>% unique %>% length -> MSreferences
TCFDB %>% pull(Reference) %>% unique %>% length -> MSreferencesTCF
TBMFDB %>% pull(Family) %>% unique %>% length -> MSfamilies
TBMFDB %>% pull(TPLName) %>% unique %>% length -> MSspecies
TBMFDB %>% pull(Year) %>% unique() %>% min -> MSoldest
TBMFDB %>% group_by(Country) %>% tally() %>% arrange(-n) -> MScountries
TBMFDB$Number_seeds %>% sum -> MSseeds
TBMFDB %>% pull(Tmean) %>% min -> MSminT
TBMFDB %>% pull(Tmean) %>% max -> MSmaxT
TBMFDB %>% filter(Alternating == "Y") %>% tally -> MSaltY
TBMFDB %>% filter(Alternating == "N") %>% tally -> MSaltN
TBMFDB %>% filter(Light == "Y") %>% tally -> MSlightY
TBMFDB %>% filter(Light == "N") %>% tally -> MSlightN
TBMFDB %>% filter(is.na(Light)) %>% tally -> MSlightNA
TBMFDB %>% filter(Stratification_type == "None") %>% tally -> MSstratN
TBMFDB %>% filter(Stratification_type == "Cold") %>% tally -> MSstratCold
TBMFDB %>% filter(Scarification == "Y") %>% tally -> MSscarY
TBMFDB %>% arrange(Reference) %>% pull(Reference) %>% unique -> MSrefapp
save(MSaltN, MSaltY, MScountries, MSlightN, MSlightNA, MSlightY,
MSrecords, MSscarY, MSstratCold, MSstratN,
MSecoregions, MSfamilies, MSfrequentspp, MSmaxT, MSminT,
MSoldest, MSplots, MSreferences, MSseeds, MSspecies, MStotalspp,
MSrefapp,
file = here::here("results", "msnumbers.RData"))
# Create files for the app
library(metafor); library(binom); library(data.table)
## A function to metanalize proportions...
metanalize <- function(d)
{
m <- rma.glmm(measure = "PLO", xi = Germinated, ni = Number_seeds, data = d)
p <- predict(m, transf = transf.ilogit, digits = 3)
data.frame(mean = p$pred, lower = p$ci.lb, upper = p$ci.ub)
}
## Data grouped by experimental and species
TBMFDB %>%
mutate(group = paste(TPLName, Scarification, Stratification_type,
Light, Alternating, Temperature, sep = "_")) %>%
data.table(.) -> df
## First we check for which groups the metanalysis works...
listd <- split(df, by = "group", drop = TRUE)
ms <- lapply(listd, function(d) tryCatch(metanalize(d), error = function(e) e))
rma.works <- names(ms)[lapply(ms, length) >= 3]
## Now we do the MA for the species that work
df.rma <- df[group %in% rma.works]
df.rma %>%
group_by(group) %>%
do(metanalize(.)) %>%
group_by -> rma.species
## And for the rest, we simply calculate the proportions and CI
df[! group %in% rma.works] %>%
group_by(group) %>%
summarise(Germinated = sum(Germinated), Number_seeds = sum(Number_seeds)) %>%
data.frame -> GermDF
cbind(group = GermDF[, 1],
binom.confint(GermDF$Germinated, GermDF$Number_seeds, method = "wilson")[, 4:6]) %>%
as_tibble()-> germdf
rbind(germdf, rma.species) %>%
separate(group, into = c("Species", "Scarification", "Stratification_type",
"Light", "Alternating", "Temperature"), sep = "_",
convert = TRUE) %>%
mutate(Light = ifelse(is.na(Light), "Light unknown", Light),
Species = as.factor(Species),
Scarification = as.factor(Scarification),
Stratification_type = as.factor(Stratification_type),
Light = as.factor(Light),
Alternating = as.factor(Alternating),
Scarification = recode_factor(Scarification, "N" = "Unscarified", "Y" = "Scarified"),
Stratification_type = recode_factor(Stratification_type, "C+W" = "C+W-stratified",
"Cold" = "Cold-stratified",
"None" = "Non-stratified",
"W+C" = "W+C-stratified",
"Warm" = "Warm-stratified"),
Light = recode_factor(Light, "N" = "Darkness", "Y" = "Light"),
Alternating = recode_factor(Alternating, "N" = "Constant temperature",
"Y" = "Alternating temperature"),
Experiment = paste(Light, Alternating, Stratification_type, Scarification, sep = ",\n"),
Experiment = as.factor(Experiment)) %>%
rename(Stratification = Stratification_type) -> Germination
## Biome map
library(raster); library(sp)
library(maps); library(mapdata); library(rgdal)
library(plyr)
## Prepare WWF shapefile
readOGR(dsn = "../#wwfmap/WWF",
layer = "wwf_terr_ecos") -> Ecoregions # Map files are in my home drive
rownames(Ecoregions@data) -> Ecoregions@data$id
fortify(Ecoregions, region = "id") -> Ecoregions.points
join(Ecoregions.points, Ecoregions@data, by = "id") %>%
inner_join(read.csv("../#wwfmap/Biomes.csv"), by = "BIOME") %>%
filter(BIOME == 4) ->
TBMF
TBMFDB %>%
dplyr::select(TPLName, Country, Latitude, Longitude) %>%
dplyr::rename(Species = TPLName) %>%
unique -> coordinates
coordinates %>%
dplyr::select(Longitude, Latitude) %>%
SpatialPoints(proj4string = CRS(proj4string(Ecoregions))) %over% Ecoregions %>%
cbind(coordinates) -> Places
save(Germination,TBMFDB, Places, TBMF,
file = here::here("results", "appdata.RData"))
# Manuscript figures
TBMFDB %>%
ggplot(aes(x = Longitude, y = Latitude)) +
geom_polygon(data = map_data("world"), aes(x = long, y = lat, group = group),
color = "gainsboro", fill = "gainsboro") +
geom_polygon(data = TBMF, aes(x = long, y = lat,group = group),
fill = "darkolivegreen4", color = "darkolivegreen4") +
geom_point(color = "gold", size = 1.25, alpha = 0.5) +
ggthemes::theme_map() +
theme(legend.position = "none",
axis.title = element_blank()) +
coord_cartesian(xlim = c(-160, 180), ylim = c(-55, 80)) -> p1
Germination %>%
filter(Species == "Fagus sylvatica") %>%
ggplot(aes(x = as.factor(Temperature), y = mean, ymin = lower, ymax = upper, fill = Experiment)) +
geom_bar(stat = "identity", alpha = 0.6, show.legend = FALSE) +
geom_errorbar(aes(color = Experiment), width = 0.1, size = 1,
position = position_dodge(.9), show.legend = FALSE) +
facet_wrap( ~ Experiment, scales = "free", ncol = 3) +
coord_cartesian(ylim = c(0, 1)) +
ylab(label = "Germination proportion") + xlab(label = "Average germination temperature (ºC)") +
ggthemes::theme_tufte() +
theme(panel.background = element_rect(color = "grey96", fill = "grey96"),
legend.position = "none",
strip.text = element_text(size = 11),
axis.text = element_text(size = 12, face = "bold"),
axis.title = element_text(size = 14, face = "bold"),
legend.text = element_text(size = 16, face = "bold")) -> p2
ggsave(p1, file = "results/Fig1.pdf",
path = NULL, scale = 1, width = 170, height = 70, units = "mm", dpi = 600)
ggsave(p2, file = "results/Fig2.pdf",
path = NULL, scale = 1, width = 170, height = 120, units = "mm", dpi = 600)
dfHeader
dfFrequentNames %>%
filter(SpeciesNew %in% TBMFspp) %>%
pull(SpeciesNew) %>% unique %>% length -> MSfrequentspp
merge(dfHeader, dfSpeciesRevised, by = "PlotID") %>%
filter(! Ecoregion %in% c("Cascade Mountains leeward forests", "Central and Southern Cascades forests",
"Eastern Cascades forests")) %>% # These ecoregions are in the vegetation db, but belong to different biome
select(New.ID) %>%
unique %>%
merge(Names, by = "New.ID") %>%
mutate(SpeciesNew = paste(New.Genus, New.Species, sep = " ")) %>%
pull(SpeciesNew) %>% unique %>% length -> MStotalspp
dfHeader %>%
filter(! Ecoregion %in% c("Cascade Mountains leeward forests", "Central and Southern Cascades forests",
"Eastern Cascades forests")) %>% # These ecoregions are in the vegetation db, but belong to different biome
pull(PlotID) %>% unique %>% length -> MSplots
dfHeader %>%
filter(! Ecoregion %in% c("Cascade Mountains leeward forests", "Central and Southern Cascades forests",
"Eastern Cascades forests")) %>% # These ecoregions are in the vegetation db, but belong to different biome
pull(Ecoregion) %>% unique %>% length -> MSecoregions
TBMFDB %>% tally() -> MSrecords
TBMFDB %>% pull(Reference) %>% unique %>% length -> MSreferences
TCFDB %>% pull(Reference) %>% unique %>% length -> MSreferencesTCF
TBMFDB %>% pull(Family) %>% unique %>% length -> MSfamilies
TBMFDB %>% pull(TPLName) %>% unique %>% length -> MSspecies
TBMFDB %>% pull(Reference) %>% unique %>% length -> MSreferences
TBMFDB %>% pull(Family) %>% unique %>% length -> MSfamilies
TBMFDB %>% pull(TPLName) %>% unique %>% length -> MSspecies
TBMFDB %>% pull(Year) %>% unique() %>% min -> MSoldest
TBMFDB %>% group_by(Country) %>% tally() %>% arrange(-n) -> MScountries
TBMFDB$Number_seeds %>% sum -> MSseeds
TBMFDB %>% pull(Tmean) %>% min -> MSminT
TBMFDB %>% pull(Tmean) %>% max -> MSmaxT
TBMFDB %>% filter(Alternating == "Y") %>% tally -> MSaltY
TBMFDB %>% filter(Alternating == "N") %>% tally -> MSaltN
TBMFDB %>% filter(Light == "Y") %>% tally -> MSlightY
TBMFDB %>% filter(Light == "N") %>% tally -> MSlightN
TBMFDB %>% filter(is.na(Light)) %>% tally -> MSlightNA
TBMFDB %>% filter(Stratification_type == "None") %>% tally -> MSstratN
TBMFDB %>% filter(Stratification_type == "Cold") %>% tally -> MSstratCold
TBMFDB %>% filter(Scarification == "Y") %>% tally -> MSscarY
TBMFDB %>% arrange(Reference) %>% pull(Reference) %>% unique -> MSrefapp
save(MSaltN, MSaltY, MScountries, MSlightN, MSlightNA, MSlightY,
MSrecords, MSscarY, MSstratCold, MSstratN,
MSecoregions, MSfamilies, MSfrequentspp, MSmaxT, MSminT,
MSoldest, MSplots, MSreferences, MSseeds, MSspecies, MStotalspp,
MSrefapp,
file = here::here("results", "msnumbers.RData"))
library(metafor); library(binom); library(data.table)
metanalize <- function(d)
{
m <- rma.glmm(measure = "PLO", xi = Germinated, ni = Number_seeds, data = d)
p <- predict(m, transf = transf.ilogit, digits = 3)
data.frame(mean = p$pred, lower = p$ci.lb, upper = p$ci.ub)
}
TBMFDB %>%
mutate(group = paste(TPLName, Scarification, Stratification_type,
Light, Alternating, Temperature, sep = "_")) %>%
data.table(.) -> df
listd <- split(df, by = "group", drop = TRUE)
ms <- lapply(listd, function(d) tryCatch(metanalize(d), error = function(e) e))
rma.works <- names(ms)[lapply(ms, length) >= 3]
df.rma <- df[group %in% rma.works]
df.rma %>%
group_by(group) %>%
do(metanalize(.)) %>%
group_by -> rma.species
df[! group %in% rma.works] %>%
group_by(group) %>%
summarise(Germinated = sum(Germinated), Number_seeds = sum(Number_seeds)) %>%
data.frame -> GermDF
cbind(group = GermDF[, 1],
binom.confint(GermDF$Germinated, GermDF$Number_seeds, method = "wilson")[, 4:6]) %>%
as_tibble()-> germdf
rbind(germdf, rma.species) %>%
separate(group, into = c("Species", "Scarification", "Stratification_type",
"Light", "Alternating", "Temperature"), sep = "_",
convert = TRUE) %>%
mutate(Light = ifelse(is.na(Light), "Light unknown", Light),
Species = as.factor(Species),
Scarification = as.factor(Scarification),
Stratification_type = as.factor(Stratification_type),
Light = as.factor(Light),
Alternating = as.factor(Alternating),
Scarification = recode_factor(Scarification, "N" = "Unscarified", "Y" = "Scarified"),
Stratification_type = recode_factor(Stratification_type, "C+W" = "C+W-stratified",
"Cold" = "Cold-stratified",
"None" = "Non-stratified",
"W+C" = "W+C-stratified",
"Warm" = "Warm-stratified"),
Light = recode_factor(Light, "N" = "Darkness", "Y" = "Light"),
Alternating = recode_factor(Alternating, "N" = "Constant temperature",
"Y" = "Alternating temperature"),
Experiment = paste(Light, Alternating, Stratification_type, Scarification, sep = ",\n"),
Experiment = as.factor(Experiment)) %>%
rename(Stratification = Stratification_type) -> Germination
Germination
library(raster); library(sp)
library(maps); library(mapdata); library(rgdal)
library(plyr)
readOGR(dsn = "../#data/wwfmap/WWF",
layer = "wwf_terr_ecos") -> Ecoregions # Map files are in my home drive
readOGR(dsn = "../#data/maps/WWF",
layer = "wwf_terr_ecos") -> Ecoregions # Map files are in my home drive
rownames(Ecoregions@data) -> Ecoregions@data$id
fortify(Ecoregions, region = "id") -> Ecoregions.points
join(Ecoregions.points, Ecoregions@data, by = "id") %>%
inner_join(read.csv("../#data/maps/Biomes.csv"), by = "BIOME") %>%
filter(BIOME == 4) ->
TBMF
TBMFDB %>%
dplyr::select(TPLName, Country, Latitude, Longitude) %>%
dplyr::rename(Species = TPLName) %>%
unique -> coordinates
coordinates %>%
dplyr::select(Longitude, Latitude) %>%
SpatialPoints(proj4string = CRS(proj4string(Ecoregions))) %over% Ecoregions %>%
cbind(coordinates) -> Places
save(Germination,TBMFDB, Places, TBMF,
file = here::here("results", "appdata.RData"))
# Manuscript figures
TBMFDB %>%
ggplot(aes(x = Longitude, y = Latitude)) +
geom_polygon(data = map_data("world"), aes(x = long, y = lat, group = group),
color = "gainsboro", fill = "gainsboro") +
geom_polygon(data = TBMF, aes(x = long, y = lat,group = group),
fill = "darkolivegreen4", color = "darkolivegreen4") +
geom_point(color = "gold", size = 1.25, alpha = 0.5) +
ggthemes::theme_map() +
theme(legend.position = "none",
axis.title = element_blank()) +
coord_cartesian(xlim = c(-160, 180), ylim = c(-55, 80)) -> p1
Germination %>%
filter(Species == "Fagus sylvatica") %>%
ggplot(aes(x = as.factor(Temperature), y = mean, ymin = lower, ymax = upper, fill = Experiment)) +
geom_bar(stat = "identity", alpha = 0.6, show.legend = FALSE) +
geom_errorbar(aes(color = Experiment), width = 0.1, size = 1,
position = position_dodge(.9), show.legend = FALSE) +
facet_wrap( ~ Experiment, scales = "free", ncol = 3) +
coord_cartesian(ylim = c(0, 1)) +
ylab(label = "Germination proportion") + xlab(label = "Average germination temperature (ºC)") +
ggthemes::theme_tufte() +
theme(panel.background = element_rect(color = "grey96", fill = "grey96"),
legend.position = "none",
strip.text = element_text(size = 11),
axis.text = element_text(size = 12, face = "bold"),
axis.title = element_text(size = 14, face = "bold"),
legend.text = element_text(size = 16, face = "bold")) -> p2
ggsave(p1, file = "results/Fig1.png",
path = NULL, scale = 1, width = 170, height = 70, units = "mm", dpi = 600)
ggsave(p2, file = "results/Fig2.png",
path = NULL, scale = 1, width = 170, height = 120, units = "mm", dpi = 600)
library(tidyverse); library(here); library(sp); library(openxlsx)
# Cleaning of the search string
## TPL Names from common source
read.csv("../#data/tpl/results/TPLNames.csv") -> Names # TPL taxonomy files are in my home drive
read.csv("../#data/tpl/results/Families.csv") -> SeedFamilies # TPL taxonomy files are in my home drive
## Clean species file
rbind(
read.csv("../#data/plots/data/sPlot12/species_Edu.csv") %>% # sPlot vegetation files are in my home drive
select(PlotObservationID, species, Relative.cover) %>%
rename(Cover = Relative.cover, PlotID = PlotObservationID, Taxon = species) %>%
mutate(PlotID = paste("Rest", PlotID, sep = "_")),
read.csv("../#data/plots/data/sPlot12/forest2_1500.csv", sep = "\t") %>% # sPlot vegetation files are in my home drive
select(Relevé.number, Species.name, Cover..) %>%
rename(Cover = Cover.., PlotID = Relevé.number, Taxon = Species.name) %>%
mutate(PlotID = paste("Japan", PlotID, sep = "_"))) %>%
merge(Names, by = "Taxon", all.x = TRUE) %>%
filter(Family %in% SeedFamilies$Family) %>%
select(PlotID, New.ID, Cover) -> dfSpeciesRevised
## Clean plot header file
rbind(
read.csv("../#data/plots/data/sPlot12/TDFNH3_Edu.csv") %>% # sPlot vegetation files are in my home drive
filter(Herbs.identified..y.n. != "N" |
! Plants.recorded %in% c("All trees & dominant shrubs",
"All woody species",
"Dominant woody plants >= 2.5 cm dbh",
"Woody plants >= 2.5 cm dbh")) %>%
select(PlotObservationID, ECO_NAME, Altitude..m., Aspect..Â..,
Slope..Â.., POINT_X, POINT_Y) %>%
rename(PlotID = PlotObservationID,
Ecoregion = ECO_NAME,
Altitude = Altitude..m.,
Aspect = Aspect..Â..,
Slope = Slope..Â..,
Longitude = POINT_X,
Latitude = POINT_Y) %>%
mutate(PlotID = paste("Rest", PlotID, sep = "_")),
read.table("../#data/plots/data/sPlot12/japan2.txt", sep = ";", header = T) %>% # sPlot vegetation files are in my home drive
select(PlotID, REALM:ECO_NAME) %>%
merge(read.csv("../#data/plots/data/sPlot12/forest2_1500.hea", sep = "\t", quote = ""), by = "PlotID") %>% # sPlot vegetation files are in my home drive
filter(BIOME == 4) %>%
select(Relevé.number, ECO_NAME, Altitude..m., Aspect....,
Slope...., DEG_LON, DEG_LAT) %>%
rename(PlotID = Relevé.number,
Ecoregion = ECO_NAME,
Altitude = Altitude..m.,
Aspect = Aspect....,
Slope = Slope....,
Longitude = DEG_LON,
Latitude = DEG_LAT) %>%
mutate(PlotID = paste("Japan", PlotID, sep = "_"),
Longitude = as.numeric(gsub("*,", ".", Longitude)),
Latitude = as.numeric(gsub("*,", ".", Latitude)))) -> dfHeader
## Calculate frequencies, filter out rare species
dfHeader %>%
select(PlotID, Ecoregion) %>%
unique %>%
group_by(Ecoregion) %>%
summarise(T = length(Ecoregion)) -> dfTotals
merge(dfSpeciesRevised, dfHeader, by = "PlotID") %>%
select(PlotID, New.ID, Ecoregion) %>%
unique %>%
group_by(Ecoregion, New.ID) %>%
summarise(N = length(New.ID)) -> dfCounts
merge(dfCounts, dfTotals, by = "Ecoregion") %>%
mutate(F = N/T) %>%
filter(F > 0.05) %>%
pull(New.ID) %>%
unique -> FrequentSpp
Names %>%
filter(New.ID %in% FrequentSpp) %>%
mutate(Species = paste(Genus, Species, sep = " "),
SpeciesNew = paste(New.Genus, New.Species, sep = " ")) %>%
select(New.ID, Species, SpeciesNew) %>%
arrange(Species) -> dfFrequentNames
merge(dfCounts, dfTotals, by = "Ecoregion") %>%
mutate(F = N/T) %>%
filter(! Ecoregion %in% c("Cascade Mountains leeward forests", "Central and Southern Cascades forests",
"Eastern Cascades forests")) %>% # These ecoregions are in the vegetation db, but belong to different biome
filter(F > 0.05) %>%
select(New.ID) %>%
unique %>%
merge(Names) %>%
mutate(Species = paste(Genus, Species, sep = " "),
SpeciesNew = paste(New.Genus, New.Species, sep = " ")) %>%
select(SpeciesNew) %>%
unique %>%
arrange(SpeciesNew) %>%
pull(SpeciesNew) -> TBMFspp