Skip to content

Commit

Permalink
add figures
Browse files Browse the repository at this point in the history
Added analysis of regional species richness, subsampled to the same sample size
  • Loading branch information
NiklasHohmann committed Feb 15, 2024
1 parent 0199d97 commit 2115761
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ In the RStudio IDE, open the file _messinian_biodiv.Rproj_. This opens the RProj
source("code/analysis.R")
```

to reproduce the results. This will (1) produce all figures in the _figs_ folder and (2) generate variables `sr_change` and `eco_ind_median` in your workspace that contain median values of species richness and ecological indices. To inspect them, use
to reproduce the results, which might take a few minutes. This will (1) produce all figures in the _figs_ folder and (2) generate variables `sr_change` and `eco_ind_median` in your workspace that contain median values of species richness and ecological indices. To inspect them, use

```R
sr_change
Expand All @@ -51,6 +51,7 @@ eco_ind_median
* _eco_timeslice_comp_regional_ : figs of comparison of ecol indices per region
* _sr_through_time_ : figs of species richness through time
* _sr_through_time_regional_ : figs of species richness through time per region
* _sr_through_time_regional_comparable_ : figs of species richness per region, subsampled to same sample size
* _.gitignore_ : untracked files
* _LICENSE_ : Apache 2.0 license text
* _messinian_biodiv.RProj_ : Rproject file
Expand Down
47 changes: 45 additions & 2 deletions code/analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cat("Running analysis, please wait...\n")
cat("Loading data\n")
messinian_db <- read.csv(file = "data/messinianDB.csv")

#### Set seet ####
#### Set seed ####
set.seed(1)

#### Replace invalid tax names with NA ####
Expand Down Expand Up @@ -86,7 +86,7 @@ for (group in group.names.ext){

#### Species richness through time for all groups in all regions ####
cat("Determining regional species richness\n")
sr_median = array(data = NA, # mean species richness
sr_median = array(data = NA, # median species richness
dim = c(length(group.names.ext), length(timebins), length(regions.ext)),
dimnames = list("group" = group.names.ext,
"timebin" = timebins,
Expand Down Expand Up @@ -159,6 +159,49 @@ for (group in c(group.names.ext)){
}
}

#### Species richness per group and region, rarefied to the same sample size ####
cat("Determining regional species richness, rarefied to same sample size\n")
sr_median_comparable = array(data = NA, # median species richness
dim = c(length(group.names.ext), length(timebins), length(regions.ext)),
dimnames = list("group" = group.names.ext,
"timebin" = timebins,
"region" = regions.ext))

for (group in group.names.ext){
# determine subsampling size
subsampleTo = Inf
for (ti in timebins){
wMed = get_from_db(group, "Western Mediterranean", ti)
eMed = get_from_db(group, "Eastern Mediterranean", ti)
PPNA = get_from_db(group, "Po Plain-Northern Adriatic", ti)
subsampleTo = min(subsampleTo, ceiling(0.8 * (min(c(length(wMed), length(eMed), length(PPNA))))))
}
for (reg in regions.ext){
Tor = get_from_db(group = group, basin = reg, timeslice = "Tortonian" )
Mes = get_from_db(group = group, basin = reg, timeslice = "pre-evaporitic Messinian" )
Zan = get_from_db(group = group, basin = reg, timeslice = "Zanclean" )
Tor_sr = rarefyTaxRichness(mySample = Tor, subsampleTo = subsampleTo, noOfRep = noOfRep)
Mes_sr = rarefyTaxRichness(mySample = Mes, subsampleTo = subsampleTo, noOfRep = noOfRep)
Zan_sr = rarefyTaxRichness(mySample = Zan, subsampleTo = subsampleTo, noOfRep = noOfRep)
sr_median_comparable[group, "Tortonian", reg] = median(Tor_sr)
sr_median_comparable[group, "pre-evaporitic Messinian", reg] = median(Mes_sr)
sr_median_comparable[group, "Zanclean", reg] = median(Zan_sr)

file_name = paste0("figs/sr_through_time_regional_comparable/sr_through_time_comp", group, "_", reg ,".pdf")
ylab = paste0("Species richness \n subsampled to ", subsampleTo, " Occurrences")
main = paste0("Species Richness ", group, " ", reg)
ylim = c(0, max(c(Tor_sr, Mes_sr, Zan_sr)))
pdf(file = file_name)
boxplot(list( "Tortonian" = Tor_sr,
"Messinian" = Mes_sr,
"Zanclean" = Zan_sr),
ylim = ylim,
ylab = ylab,
main = main)
dev.off()
}
}


#### Changes in sr & eco indexes ####
sr_change = array(data = NA,
Expand Down
Empty file.

0 comments on commit 2115761

Please sign in to comment.