Last updated: 2021-05-20

Checks: 7 0

Knit directory: booksn_dispersantes/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.

Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20210428) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 0bb400c. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:

Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/.DS_Store

Unstaged changes:
    Modified:   data/passerine_ab.csv
    Modified:   output/abundance_time/passerine_abtotal.csv
    Modified:   output/abundance_time/passerine_abtotal_compare.csv
    Modified:   output/abundance_time/plot_all_cumbres.pdf
    Modified:   output/abundance_time/plot_all_enebral.pdf
    Modified:   output/abundance_time/plot_all_robledal.pdf
    Modified:   output/abundance_time/plot_selected_cumbres.pdf
    Modified:   output/abundance_time/plot_selected_enebral.pdf
    Modified:   output/abundance_time/plot_selected_robledal.pdf
    Modified:   output/betadiversity/betapart.csv
    Modified:   output/betadiversity/plot_betadiversity.pdf
    Modified:   output/betadiversity/tbi.csv
    Modified:   output/compose_plot.pdf
    Modified:   output/diversity/alfa_diversity.csv
    Modified:   output/diversity/diversity_habitat.pdf
    Modified:   output/diversity/richness.csv
    Modified:   output/mktrend/plot_mktrend.pdf

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.

These are the previous versions of the repository in which changes were made to the R Markdown (analysis/temporal-beta-diversity.Rmd) and HTML (docs/temporal-beta-diversity.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
html 556d988 Antonio J Perez-Luque 2021-05-20 Build site.
html c5e6571 Antonio J Perez-Luque 2021-05-10 Build site.
html 684a3f9 Antonio J Perez-Luque 2021-05-07 Build site.
html 3273236 Antonio J Perez-Luque 2021-05-04 Build site.
html 7369da6 Antonio J Perez-Luque 2021-05-04 Build site.
Rmd 8294f1d Antonio J Perez-Luque 2021-05-04 wflow_publish(“analysis/temporal-beta-diversity.Rmd”)

Explore temporal beta diversity

Computation of Temporal Beta Diversity Index

  • For each location we explore the TBI (see Legrende 2019) in three temporal times: t0 (1982), t1 (2010), t2(2019)
knitr::opts_chunk$set(echo = TRUE, 
                      warning = FALSE, 
                      message = FALSE)
  • Read data and compute the abundance average by year
passerine <- read_csv(here::here("data/passerine.csv")) 
passerine_abbreviations <- read_csv(here::here("data/passerine_abbrev.csv")) 

passerine.ab <- passerine %>% 
  rename(sp = %>% 
  dplyr::select(-especie) %>% 
  group_by(sp, year, habitat) %>% 
  summarise(ab_avg = round(mean(den, na.rm=TRUE),2), 
            sd = sd(den, na.rm = TRUE), 
            se = sd/sqrt(length(den)), 
            n = length(den)) 
  • Prepare data for Temporal Beta Diversity analysis:

    • generate a site.year variable = “site”.“year”
    • transpose from long to wide format to get sites as rows and especies as column
    • abundance values as values
    • NA values are filled with 0
df <- passerine.ab %>% 
  unite("site", habitat:year, sep="_", remove = FALSE) %>% 
  dplyr::select(-sd, -se, -n) %>% 
  pivot_wider(names_from = sp, 
              values_from = ab_avg, 
              values_fill = 0)

TBI summit habitat

  • years selected: 1982, 2008, 2018
cumbres <- df %>% 
  filter(habitat == "cumbres") %>% 
  dplyr::select(-year) %>% 
  column_to_rownames(var="site") %>% 
    negate(function(x) is.numeric(x) && sum(x) == 0)) %>% 

years <- df %>% filter(habitat == "cumbres") %>% arrange(year) %>% pull(year) 

years_selected <- c(1982, 2008, 2018)

tbi_summits <- computeTBI(cumbres, vector.years = years_selected, y0=1982)

TBI juniper habitat

  • years selected: 1984, 2008, 2018
enebral <- df %>% 
  filter(habitat == "enebral") %>% 
  dplyr::select(-year) %>% 
  column_to_rownames(var="site") %>% 
    negate(function(x) is.numeric(x) && sum(x) == 0)) %>% 
years <- df %>% filter(habitat == "enebral") %>% arrange(year) %>% pull(year) 
years_selected <- c(1984, 2008, 2018)

tbi_juniper <- computeTBI(enebral, vector.years = years_selected, y0 = 1984)

TBI oak habitat

  • years selected: 1981, 2008, 2018
robledal <- df %>% 
  filter(habitat == "robledal") %>% 
  dplyr::select(-year) %>% 
  column_to_rownames(var="site") %>% 
    negate(function(x) is.numeric(x) && sum(x) == 0)) %>% 
years <- df %>% filter(habitat == "robledal") %>% arrange(year) %>% pull(year) 
years_selected <- c(1981, 2008, 2018)

tbi_robledal <- computeTBI(robledal, vector.years = years_selected, y0 = 1981)

Explore dissimilarities

d <- bind_rows(tbi_summits, tbi_juniper, tbi_robledal) %>% 
  mutate(year_t0common = "1980's") %>% 
  rename("losses" = `mean(B/den)`,
         "gains" = `mean(C/den)`,
         "D" = `mean(D)`) %>% 
  unite("pair", year_t0common, year_t1, sep="-") %>% 
  dplyr::select(habitat:D, Change) 

write_csv(d, file=here::here("output/betadiversity/tbi.csv"))

DT::datatable(d) %>% DT::formatRound(columns = c("losses", "gains", "D"), digits=3)
cols <- c("cumbres" = "#8d96a3", "enebral" = "#66a182", "robledal" = "#edae49")
plot_BD <- d %>% 
  ggplot(aes(x=pair, fill=habitat, colour=habitat)) +
  geom_bar(aes(y=D), stat="identity", position = position_dodge2(width = .9)) + 
  ylab(expression(paste("Dissimilarity in ", beta, "-diversisty"))) +
  xlab("") + 
  theme_bw() +
  scale_color_manual(values = cols) + 
  scale_fill_manual(values = cols) + 
  geom_point(aes(x=pair, y=losses), colour="black", shape=25, 
             position = position_dodge2(width = .9)) 

       width = 12, height = 10, units = "cm")

Version Author Date
556d988 Antonio J Perez-Luque 2021-05-20
7369da6 Antonio J Perez-Luque 2021-05-04
null device 

BetaPart Analysis

b.cumbres <- betapart.core.abund(cumbres[,-c(1:2)])
bd.cumbres <- beta.multi.abund(b.cumbres, = "bray")

b.enebral <- betapart.core.abund(enebral[,-c(1:2)])
bd.enebral <- beta.multi.abund(b.enebral, = "bray")

b.robledal <- betapart.core.abund(robledal[,-c(1:2)])
bd.robledal <- beta.multi.abund(b.robledal, = "bray")

bd <- cbind(data.frame(robledal = unlist(bd.robledal)),
      data.frame(enebral = unlist(bd.enebral)),
      data.frame(cumbres = unlist(bd.cumbres))) %>% 
  rownames_to_column("variable") %>% 
  pivot_longer(robledal:cumbres, names_to = "habitat") 

write.csv(bd, file=here::here("output/betadiversity/betapart.csv"))

DT::datatable(bd) %>% DT::formatRound("value", digits=3)

R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.3

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] betapart_1.5.4    DT_0.17           adespatial_0.3-14 plotly_4.9.3     
 [5] here_1.0.1        forcats_0.5.1     stringr_1.4.0     dplyr_1.0.4      
 [9] purrr_0.3.4       readr_1.4.0       tidyr_1.1.2       tibble_3.0.6     
[13] ggplot2_3.3.3     tidyverse_1.3.0   workflowr_1.6.2  

loaded via a namespace (and not attached):
  [1] snow_0.4-3          readxl_1.3.1        uuid_0.1-4         
  [4] backports_1.2.1     fastmatch_1.1-0     plyr_1.8.6         
  [7] igraph_1.2.6        lazyeval_0.2.2      sp_1.4-5           
 [10] splines_4.0.2       crosstalk_1.1.1     rncl_0.8.4         
 [13] digest_0.6.27       foreach_1.5.1       htmltools_0.5.1.1  
 [16] gdata_2.18.0        magrittr_2.0.1      cluster_2.1.0      
 [19] modelr_0.1.8        gmodels_2.18.1      prettyunits_1.1.1  
 [22] jpeg_0.1-8.1        colorspace_2.0-0    rvest_0.3.6        
 [25] haven_2.3.1         xfun_0.20           crayon_1.4.1       
 [28] jsonlite_1.7.2      phylobase_0.8.10    iterators_1.0.13   
 [31] ape_5.4-1           glue_1.4.2          gtable_0.3.0       
 [34] seqinr_4.2-5        adegraphics_1.0-15  abind_1.4-5        
 [37] scales_1.1.1        DBI_1.1.1           Rcpp_1.0.6         
 [40] viridisLite_0.3.0   xtable_1.8-4        progress_1.2.2     
 [43] spData_0.3.8        magic_1.5-9         units_0.6-7        
 [46] spdep_1.1-5         htmlwidgets_1.5.3   httr_1.4.2         
 [49] RColorBrewer_1.1-2  ellipsis_0.3.1      farver_2.0.3       
 [52] pkgconfig_2.0.3     XML_3.99-0.5        sass_0.3.1         
 [55] dbplyr_2.1.0        deldir_0.2-9        labeling_0.4.2     
 [58] tidyselect_1.1.0    rlang_0.4.10        reshape2_1.4.4     
 [61] later_1.1.0.1       munsell_0.5.0       adephylo_1.1-11    
 [64] cellranger_1.1.0    tools_4.0.2         cli_2.3.0          
 [67] generics_0.1.0      ade4_1.7-16         broom_0.7.4        
 [70] geometry_0.4.5      evaluate_0.14       fastmap_1.1.0      
 [73] yaml_2.2.1          knitr_1.31          fs_1.5.0           
 [76] nlme_3.1-152        whisker_0.4         mime_0.10          
 [79] adegenet_2.1.3      xml2_1.3.2          compiler_4.0.2     
 [82] rstudioapi_0.13     png_0.1-7           e1071_1.7-4        
 [85] reprex_1.0.0        bslib_0.2.4         RNeXML_2.4.5       
 [88] stringi_1.5.3       highr_0.8           lattice_0.20-41    
 [91] Matrix_1.3-2        classInt_0.4-3      vegan_2.5-7        
 [94] permute_0.9-5       vctrs_0.3.6         pillar_1.4.7       
 [97] LearnBayes_2.15.1   lifecycle_1.0.0     jquerylib_0.1.3    
[100] data.table_1.13.6   raster_3.4-5        httpuv_1.5.5       
[103] R6_2.5.0            latticeExtra_0.6-29 promises_1.2.0.1   
[106] KernSmooth_2.23-18  codetools_0.2-18    rcdd_1.2-2         
[109] boot_1.3-26         MASS_7.3-53         gtools_3.8.2       
[112] assertthat_0.2.1    picante_1.8.2       rprojroot_2.0.2    
[115] withr_2.4.1         mgcv_1.8-33         expm_0.999-6       
[118] parallel_4.0.2      hms_1.0.0           doSNOW_1.0.19      
[121] grid_4.0.2          coda_0.19-4         class_7.3-18       
[124] rmarkdown_2.6.6     git2r_0.28.0        itertools_0.1-3    
[127] sf_0.9-7            shiny_1.6.0         lubridate_1.7.10