Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
efernandezpascual committed Oct 12, 2020
1 parent 065c4f9 commit 7cff597
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 136 deletions.
262 changes: 131 additions & 131 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -1,69 +1,84 @@
Stratification,
Light,
Photoperiod,
Alternating,
Tdif,
Tmax,
Tmin,
Tmean,
Temperature,
Germinated,
Number_seeds) %>%
rename(Reference = ReferenceRevised) ->
WoSDB
WoSDB %>%
filter(Biome == "TBMF") %>%
select(-Biome) -> TBMFDB # Temperate broadleaf and mixed forest database
WoSDB %>%
filter(Biome == "TCF") %>%
select(-Biome) -> TCFDB # Temperate coniferous forest database
readr::write_excel_csv(TBMFDB, here::here("results", "TBMF_Database.csv"))
readr::write_excel_csv(TCFDB, here::here("results", "TCF_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)) +
Expand Down Expand Up @@ -98,23 +113,57 @@ ggsave(p2, file = "results/Fig2.tiff",
path = NULL, scale = 1, width = 170, height = 150, units = "mm", dpi = 600)
save(p1, p2,
file = here::here("results", "msfigs.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))
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
ggsave(p1, file = "results/Fig1.tiff",
path = NULL, scale = 1, width = 170, height = 70, units = "mm", dpi = 600)
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.tiff",
path = NULL, scale = 1, width = 170, height = 70, units = "mm", dpi = 600)
ggsave(p2, file = "results/Fig2.tiff",
path = NULL, scale = 1, width = 170, height = 150, units = "mm", dpi = 600)
ggsave(p1, file = "results/Fig1.tiff",
path = NULL, scale = 1, width = 170, height = 70, units = "mm", dpi = 600)
ggsave(p2, file = "results/Fig2.tiff",
path = NULL, scale = 1, width = 170, height = 150, units = "mm", dpi = 600)
save(p1, p2,
file = here::here("results", "msfigs.RData"))
remotes::install_github('yihui/knitr')
remotes::install_github('yihui/knitr')
install.packaged("knitr")
install.packages("knitr")
install.packages("knitr")
install.packages("knitr")
install.packages("knitr")
remotes::install_github('yihui/knitr')
remotes::install_github('yihui/knitr')
install.packages("glue")
install.packages("glue")
remotes::install_github('yihui/knitr')
library(tidyverse); library(here); library(sp); library(openxlsx)
# Cleaning of the search string
## TPL Names from common source
Expand Down Expand Up @@ -432,46 +481,11 @@ 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 = 0.75, 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, face = "bold"),
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.tiff",
path = NULL, scale = 1, width = 170, height = 70, units = "mm", dpi = 600)
ggsave(p2, file = "results/Fig2.tiff",
path = NULL, scale = 1, width = 170, height = 150, units = "mm", dpi = 600)
save(p1, p2,
file = here::here("results", "msfigs.RData"))
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
ggsave(p1, file = "results/Fig1.tiff",
path = NULL, scale = 1, width = 170, height = 70, units = "mm", dpi = 600)
Germination %>%
filter(Species == "Fagus sylvatica") %>%
ggplot(aes(x = as.factor(Temperature), y = mean, ymin = lower, ymax = upper, fill = Experiment)) +
Expand All @@ -488,25 +502,11 @@ 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.tiff",
path = NULL, scale = 1, width = 170, height = 70, units = "mm", dpi = 600)
ggsave(p2, file = "results/Fig2.tiff",
path = NULL, scale = 1, width = 170, height = 150, units = "mm", dpi = 600)
ggsave(p1, file = "results/Fig1.tiff",
ggsave(p1, file = "results/Fig1.png",
path = NULL, scale = 1, width = 170, height = 70, units = "mm", dpi = 600)
ggsave(p2, file = "results/Fig2.tiff",
ggsave(p2, file = "results/png.tiff",
path = NULL, scale = 1, width = 170, height = 150, units = "mm", dpi = 600)
save(p1, p2,
file = here::here("results", "msfigs.RData"))
remotes::install_github('yihui/knitr')
remotes::install_github('yihui/knitr')
install.packaged("knitr")
install.packages("knitr")
install.packages("knitr")
install.packages("knitr")
install.packages("knitr")
remotes::install_github('yihui/knitr')
remotes::install_github('yihui/knitr')
install.packages("glue")
install.packages("glue")
remotes::install_github('yihui/knitr')
ggsave(p2, file = "results/Fig2.png",
path = NULL, scale = 1, width = 170, height = 150, units = "mm", dpi = 600)
Loading

0 comments on commit 7cff597

Please sign in to comment.