Last updated: 2022-09-16

Checks: 7 0

Knit directory: ms_mariposas_biodiversity/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). 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(20211228) 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 a449c23. 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

Untracked files:
    Untracked:  data/Density.aux.xml
    Untracked:  data/Diversity_v2.aux.xml
    Untracked:  data/Richness.aux.xml
    Untracked:  data/density.ovr
    Untracked:  data/density/
    Untracked:  data/diversity_v2.ovr
    Untracked:  data/diversity_v2/
    Untracked:  data/richness.ovr
    Untracked:  data/richness_v2.aux.xml
    Untracked:  data/richness_v2/
    Untracked:  figs/cor_den_div_np.png
    Untracked:  figs/cor_den_div_p.png
    Untracked:  figs/cor_den_rich_np.png
    Untracked:  figs/cor_den_rich_p.png
    Untracked:  figs/cor_div_ric_np.png
    Untracked:  figs/cor_div_ric_p.png

Unstaged changes:
    Modified:   .Rprofile
    Modified:   .gitattributes
    Modified:   .gitignore
    Modified:   CITATION.cff
    Modified:   README.md
    Modified:   _workflowr.yml
    Modified:   analysis/_site.yml
    Modified:   analysis/about.Rmd
    Modified:   analysis/index.Rmd
    Modified:   analysis/license.Rmd
    Modified:   analysis/modeliza.Rmd
    Modified:   analysis/plot_variables_elevation.Rmd
    Modified:   analysis/plot_variables_elevation_all_years.Rmd
    Modified:   analysis/plots_descriptores.Rmd
    Modified:   analysis/prepara_datos_mariposas.Rmd
    Modified:   analysis/prepara_datos_mariposas_all_years.Rmd
    Modified:   analysis/prepara_matrix_ambiental.Rmd
    Modified:   analysis/tabla_descriptivos.Rmd
    Modified:   analysis/tabla_suplementaria.Rmd
    Modified:   code/README.md
    Modified:   data/Mariposas_2008_2021.xlsx
    Modified:   data/README.md
    Modified:   data/Tabla_variables_2012_2020.xls
    Modified:   data/Tabla_variables_modelización_lepidópteros_ACTUALIZADO_2020.xlsx
    Modified:   data/climate_year.csv
    Modified:   data/densidad_by_year.csv
    Modified:   data/densidad_by_year_alldata.csv
    Modified:   data/diversidad_by_year.csv
    Modified:   data/diversidad_by_year_alldata.csv
    Modified:   data/longitud_transectos.xlsx
    Modified:   data/mariposas_diurnas_contactos_transectos.csv
    Modified:   data/mariposas_diurnas_visitas.csv
    Modified:   data/matrix_env_variables_selected.csv
    Modified:   data/mod_den_coefficients.csv
    Modified:   data/mod_den_selectionBIC.csv
    Modified:   data/mod_div_coefficients.csv
    Modified:   data/mod_div_selectionBIC.csv
    Modified:   data/mod_riq_coefficients.csv
    Modified:   data/mod_riq_selectionBIC.csv
    Modified:   data/riqueza_by_site.csv
    Modified:   data/riqueza_by_year.csv
    Modified:   data/riqueza_by_year_alldata.csv
    Modified:   data/supplementary_species.xlsx
    Modified:   data/supplementary_taxones.xlsx
    Modified:   data/tabla_4-v2.xlsx
    Modified:   data/tabla_descriptivos.csv
    Modified:   data/tabla_especies_transectos.csv
    Modified:   data/tabla_taxones_transectos.csv
    Modified:   data/transect_abrev.csv
    Modified:   data/transectos_tabla.csv
    Modified:   figs/contactos_elevation_by_sp.pdf
    Modified:   figs/correlation_env_variables.pdf
    Modified:   figs/correlation_env_variables_numbers.pdf
    Modified:   figs/dendrograma_env.pdf
    Modified:   figs/plot_rarefaction.pdf
    Modified:   figs/plot_species_acumulation_area.pdf
    Modified:   figs/plot_variables_elevation.pdf
    Modified:   figs/plot_variables_elevation.png
    Modified:   figs/plot_variables_elevation_allyears.pdf
    Modified:   figs/plot_variables_elevation_allyears.png
    Modified:   figs/predictors_den_div.pdf
    Modified:   figs/predictors_den_div.png
    Modified:   figs/predictors_rich.pdf
    Modified:   glmulti.analysis.modgen.back
    Modified:   glmulti.analysis.mods.back
    Modified:   ms_mariposas_biodiversity.Rproj
    Modified:   output/README.md

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/plot_correlations.Rmd) and HTML (docs/plot_correlations.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
Rmd a449c23 ajpelu 2022-09-16 add correlations

Prepare data

library(tidyverse)
library(raster)
library(fasterize)
library(rgdal)
library(ggpubr)
library(ggstatsplot)
Warning: package 'ggstatsplot' was built under R version 4.0.5
Warning: replacing previous import 'dplyr::collapse' by 'glue::collapse' when
loading 'statsExpressions'
library(here)
library(statsExpressions)
Warning: package 'statsExpressions' was built under R version 4.0.5
den <- raster::raster(here::here("data/density.ovr"))
riq <- raster::raster(here::here("data/richness.ovr"))
div <- raster::raster(here::here("data/diversity_v2.ovr"))

s <- stack(den, riq, div)

df <- as.data.frame(s, xy=TRUE) %>% 
  filter(!is.na(density))

Non-parametric

cor_den_rich_np <- ggscatterstats(df, 
               x = density, y = richness, 
               marginal = FALSE, 
               type = "parametric", 
               point.args = list(fill="gray", alpha = 0.8),
               smooth.line.args = 
                 list(method = "gam", formula = y ~ s(x, bs = "cs"),
                      color = "blue"))
cor_den_rich_np

cor_den_div_np <- ggscatterstats(df, 
               x = density, y = diversity_v2, 
               marginal = FALSE, 
               type = "nonparametric",
               point.args = list(fill="gray", alpha = 0.2),
               smooth.line.args = 
                 list(method = "gam", formula = y ~ s(x, bs = "cs"),
                      color = "blue"))
cor_den_div_np

cor_div_ric_np <-  ggscatterstats(df, 
                               y = richness, x = diversity_v2, 
                               marginal = FALSE, 
                               type = "nonparametric",
                               point.args = list(fill="gray", alpha = 0.2),
                               smooth.line.args = 
                                 list(method = "gam", formula = y ~ s(x, bs = "cs"),
                                      color = "blue"))
cor_div_ric_np

ggsave(
  filename = "figs/cor_den_rich_np.png",
  plot = cor_den_rich_np,
  width = 8,
  height = 8,
  device = "png"
)

ggsave(
  filename = "figs/cor_den_div_np.png",
  plot = cor_den_div_np,
  width = 8,
  height = 8,
  device = "png"
)

ggsave(
  filename = "figs/cor_div_ric_np.png",
  plot = cor_div_ric_np,
  width = 8,
  height = 8,
  device = "png"
)

Parametric

mylabel <- c(
  den = "Abundance (n ind / 100 m)",
  div = "Diversity (Shannon index)",
  riq = "Richness (species number)")
ct <- corr_test(df, x = density, y = richness, type = "parametric")

cor_den_rich_p <- ggplot(df, aes(x=density, y=richness)) + 
  geom_point(col="gray", size=.3, alpha=.2) + 
  theme_minimal() + 
  geom_smooth(method = "gam", 
              formula = y ~ s(x, bs = "cs"),
              color = "blue", 
              size =.5) + 
  labs(subtitle = ggplot2::expr(paste(
    widehat(italic("r"))["Pearson"], "=0.727, ", italic("p"), "<", "0.001")),
    x = mylabel["den"], 
    y = mylabel["riq"])

cor_den_rich_p

ct <- corr_test(df, x = density, y = diversity_v2, type = "parametric")

cor_den_div_p <- ggplot(df, aes(x = density, y = diversity_v2)) + 
  geom_point(col="gray", size=.3, alpha=0.2) + 
  theme_minimal() + 
  geom_smooth(method = "gam", 
              formula = y ~ s(x, bs = "cs"),
              color = "blue", 
              size =.5) + 
  labs(subtitle = ggplot2::expr(paste(
    widehat(italic("r"))["Pearson"], "=0.773, ", italic("p"), "<", "0.001")),
    x = mylabel["den"], 
    y = mylabel["div"])
cor_den_div_p

ct <- corr_test(df, x = diversity_v2, y = richness, type = "parametric")

cor_div_ric_p <- ggplot(df, aes(x = diversity_v2, y = richness)) + 
  geom_point(col="gray", size=.3, alpha=0.2) + 
  theme_minimal() + 
  geom_smooth(method = "gam", 
              formula = y ~ s(x, bs = "cs"),
              color = "blue", 
              size =.5) + 
  labs(subtitle = ggplot2::expr(paste(
    widehat(italic("r"))["Pearson"], "=0.673, ", italic("p"), "<", "0.001")),
    x = mylabel["div"],
    y = mylabel["riq"])

cor_div_ric_p

ggsave(
  filename = "figs/cor_den_rich_p.png",
  plot = cor_den_rich_p,
  width = 8,
  height = 8,
  device = "png"
)

ggsave(
  filename = "figs/cor_den_div_p.png",
  plot = cor_den_div_p,
  width = 8,
  height = 8,
  device = "png"
)

ggsave(
  filename = "figs/cor_div_ric_p.png",
  plot = cor_div_ric_p,
  width = 8,
  height = 8,
  device = "png"
)

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

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

locale:
[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] statsExpressions_1.3.1 here_1.0.1             ggstatsplot_0.9.1     
 [4] ggpubr_0.4.0           rgdal_1.5-23           fasterize_1.0.3       
 [7] raster_3.4-5           sp_1.4-5               forcats_0.5.1         
[10] stringr_1.4.0          dplyr_1.0.6            purrr_0.3.4           
[13] readr_1.4.0            tidyr_1.1.3            tibble_3.1.2          
[16] ggplot2_3.3.5          tidyverse_1.3.1        workflowr_1.7.0       

loaded via a namespace (and not attached):
  [1] TH.data_1.0-10         colorspace_2.0-2       ggsignif_0.6.3        
  [4] ellipsis_0.3.2         rio_0.5.16             rprojroot_2.0.2       
  [7] estimability_1.3       parameters_0.17.0      fs_1.5.0              
 [10] mc2d_0.1-18            rstudioapi_0.13        farver_2.1.0          
 [13] MatrixModels_0.4-1     fansi_0.4.2            mvtnorm_1.1-1         
 [16] lubridate_1.7.10       xml2_1.3.2             codetools_0.2-18      
 [19] splines_4.0.2          knitr_1.31             zeallot_0.1.0         
 [22] jsonlite_1.7.2         broom_0.7.9            dbplyr_2.1.1          
 [25] effectsize_0.6.0.1     compiler_4.0.2         httr_1.4.2            
 [28] emmeans_1.5.4          backports_1.2.1        assertthat_0.2.1      
 [31] Matrix_1.3-2           fastmap_1.1.0          cli_2.5.0             
 [34] later_1.1.0.1          htmltools_0.5.2        tools_4.0.2           
 [37] coda_0.19-4            gtable_0.3.0           glue_1.4.2            
 [40] Rcpp_1.0.7             carData_3.0-4          cellranger_1.1.0      
 [43] jquerylib_0.1.3        vctrs_0.3.8            nlme_3.1-152          
 [46] insight_0.17.0         xfun_0.30              ps_1.5.0              
 [49] openxlsx_4.2.3         rvest_1.0.0            lifecycle_1.0.1       
 [52] gtools_3.8.2           rstatix_0.6.0          getPass_0.2-2         
 [55] MASS_7.3-53            zoo_1.8-8              scales_1.1.1.9000     
 [58] BayesFactor_0.9.12-4.3 ragg_1.1.1             hms_1.0.0             
 [61] promises_1.2.0.1       parallel_4.0.2         sandwich_3.0-0        
 [64] rematch2_2.1.2         yaml_2.2.1             curl_4.3.2            
 [67] pbapply_1.4-3          sass_0.4.1             reshape_0.8.8         
 [70] stringi_1.7.4          highr_0.8              paletteer_1.3.0       
 [73] bayestestR_0.11.5      zip_2.1.1              systemfonts_1.0.0     
 [76] rlang_0.4.12           pkgconfig_2.0.3        evaluate_0.14         
 [79] lattice_0.20-41        labeling_0.4.2         patchwork_1.1.1       
 [82] processx_3.5.1         tidyselect_1.1.1       plyr_1.8.6            
 [85] magrittr_2.0.1         R6_2.5.1               generics_0.1.0        
 [88] multcomp_1.4-16        DBI_1.1.1              mgcv_1.8-33           
 [91] pillar_1.6.1           haven_2.3.1            whisker_0.4           
 [94] foreign_0.8-81         withr_2.5.0            survival_3.2-7        
 [97] datawizard_0.4.0       abind_1.4-5            performance_0.8.0     
[100] WRS2_1.1-3             modelr_0.1.8           crayon_1.4.1          
[103] car_3.0-10             utf8_1.1.4             correlation_0.8.0     
[106] rmarkdown_2.14         grid_4.0.2             readxl_1.3.1          
[109] data.table_1.14.0      callr_3.7.0            git2r_0.28.0          
[112] reprex_2.0.0           digest_0.6.27          xtable_1.8-4          
[115] httpuv_1.5.5           textshaping_0.3.2      munsell_0.5.0         
[118] bslib_0.3.1