Last updated: 2022-01-18

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 8f1c7af. 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/

Untracked files:
    Untracked:  data/Tabla_variables_modelización_lepidópteros_ACTUALIZADO_2020.xlsx
    Untracked:  data/tabla_descriptivos.csv

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/tabla_descriptivos.Rmd) and HTML (docs/tabla_descriptivos.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 8f1c7af ajpelu 2022-01-18 wflow_publish(“analysis/tabla_descriptivos.Rmd”)

Introduction

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
✓ ggplot2 3.3.5     ✓ purrr   0.3.4
✓ tibble  3.1.2     ✓ dplyr   1.0.6
✓ tidyr   1.1.3     ✓ stringr 1.4.0
✓ readr   1.4.0     ✓ forcats 0.5.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()
library(here)
here() starts at /Volumes/GoogleDrive/My Drive/MS/2021_MS_MARIPOSAS/ms_mariposas_biodiversity
library(kableExtra)

Attaching package: 'kableExtra'
The following object is masked from 'package:dplyr':

    group_rows
  • Read data
denraw <- read_csv(here::here("data/densidad_by_year.csv")) 

── Column specification ────────────────────────────────────────────────────────
cols(
  id_transecto = col_character(),
  transecto = col_character(),
  site = col_character(),
  elev = col_double(),
  year = col_double(),
  abundancia = col_double(),
  long_total = col_double(),
  den = col_double()
)
divraw <- read_csv(here::here("data/diversidad_by_year.csv")) 

── Column specification ────────────────────────────────────────────────────────
cols(
  diversidad = col_double(),
  year = col_double(),
  transecto = col_character(),
  longitud = col_double(),
  min_altitu = col_double(),
  max_altitu = col_double(),
  id_transecto = col_character(),
  site = col_character(),
  elev = col_double()
)
riqraw <- read_csv(here::here("data/riqueza_by_year.csv"))

── Column specification ────────────────────────────────────────────────────────
cols(
  transecto = col_character(),
  year = col_double(),
  riq = col_double(),
  longitud = col_double(),
  min_altitu = col_double(),
  max_altitu = col_double(),
  id_transecto = col_character(),
  site = col_character(),
  elev = col_double()
)
richness <- read_csv(here::here("data/riqueza_by_site.csv"))

── Column specification ────────────────────────────────────────────────────────
cols(
  transecto = col_character(),
  riq = col_double(),
  longitud = col_double(),
  min_altitu = col_double(),
  max_altitu = col_double(),
  id_transecto = col_character(),
  site = col_character(),
  elev = col_double()
)
transectos <- read_csv(here::here("data/transectos_tabla.csv"))

── Column specification ────────────────────────────────────────────────────────
cols(
  transecto = col_character(),
  longitud = col_double(),
  min_altitu = col_double(),
  max_altitu = col_double(),
  id_transecto = col_character(),
  site = col_character(),
  elev = col_double()
)
densidad_avg <- denraw %>%
  group_by(transecto, site, elev) %>%
  summarise(mean = mean(den, na.rm = TRUE),
            sd = sd(den, na.rm = TRUE),
            se = sd/sqrt(n()))
`summarise()` has grouped output by 'transecto', 'site'. You can override using the `.groups` argument.
diversidad_avg <- divraw %>%
  group_by(transecto, site, elev) %>%
  summarise(mean = mean(diversidad, na.rm = TRUE),
            sd = sd(diversidad, na.rm = TRUE),
            se = sd/sqrt(n()))
`summarise()` has grouped output by 'transecto', 'site'. You can override using the `.groups` argument.
abundancia <- denraw %>%
  group_by(transecto, site) %>%
  summarise(mean = round(mean(abundancia),2),
            sd = sd(abundancia),
            se = round(sd/sqrt(n()),2),
            n_ind_total = sum(abundancia))
`summarise()` has grouped output by 'transecto'. You can override using the `.groups` argument.
descriptivos <- 
  transectos %>% inner_join(densidad_avg) %>%
  dplyr::select(-sd) %>%
  mutate(mean = round(mean, 2),
         se = round(se,2)) %>%
  unite("density", mean,se, sep = " ± ") %>% 
  inner_join(diversidad_avg) %>%
  dplyr::select(-sd) %>%
  mutate(mean = round(mean, 2),
         se = round(se,2)) %>%
  unite("diversity", mean,se, sep = " ± ") %>%
  inner_join(richness) %>%
  rename(richness = riq) %>%
  inner_join(abundancia) %>%
  dplyr::select(-sd) %>%
  unite("abundancia_media", mean,se, sep = " ± ") %>% 
  unite("elev_rango", min_altitu, max_altitu, sep = "-") %>% 
  rowwise() %>% 
  mutate(elev_rango = paste0("(", elev_rango, ")")) %>% 
  unite("Elevation", elev, elev_rango, sep=" ") %>% 
  dplyr::select(
    "Transect" = transecto,
    "Code" = site,
    Elevation,
    "Length" = longitud,
    "Abundance" = density,
    "Diversity (H’)" = diversity,
    "Richness" = richness,
    "Mean number of individuals" = abundancia_media,
    "Total number of individuals" = n_ind_total)
Joining, by = c("transecto", "site", "elev")
Joining, by = c("transecto", "site", "elev")
Joining, by = c("transecto", "longitud", "min_altitu", "max_altitu", "id_transecto", "site", "elev")
Joining, by = c("transecto", "site")
write_csv(descriptivos, here::here("data/tabla_descriptivos.csv"))
descriptivos %>% 
  kbl() %>% 
  kable_styling()
Transect Code Elevation Length Abundance Diversity (H’) Richness Mean number of individuals Total number of individuals
Altas cumbres AC 3126 (3081-3170) 3209 0.47 ± 0.03 1.02 ± 0.17 16 82.12 ± 10.04 657
Barranco de San Juan BSJ 1362 (1347-1377) 453 5.52 ± 0.63 2.92 ± 0.05 73 236.5 ± 38.17 1892
Borreguiles San Juan BOSJ 2545 (2527-2563) 2533 2.38 ± 0.27 2.49 ± 0.04 45 378.38 ± 45.91 3027
Campos de Otero CO 2248 (2178-2317) 2992 4.06 ± 0.48 2.67 ± 0.04 70 986.12 ± 157.42 7889
Carihuela CAR 2808 (2792-2824) 387 0.56 ± 0.1 1.02 ± 0.14 9 9 ± 1.35 72
Catifas CAT 1666 (1658-1673) 483 4.18 ± 0.27 2.75 ± 0.07 63 190.62 ± 22.05 1525
Cauchiles CAU 3203 (3196-3210) 624 1.08 ± 0.37 1.41 ± 0.19 18 28.12 ± 5.59 225
Dúrcal DU 1950 (1913-1987) 3563 9.41 ± 0.99 3.05 ± 0.04 64 3038.86 ± 331.97 21272
Fabriquilla FA 992 (971-1013) 415 2.47 ± 0.25 2.43 ± 0.06 56 88.5 ± 18.88 708
Laguna Seca LS 2282 (2257-2306) 3044 3.15 ± 0.46 1.85 ± 0.1 38 754.5 ± 119 6036
Laguna LP 732 (726-739) 500 3.95 ± 0.35 0.96 ± 0.13 24 193.14 ± 22.83 1352
Matas Verdes MV 1919 (1851-1987) 2672 5.23 ± 0.61 2.87 ± 0.12 78 1277.25 ± 168.91 10218
Loma de Papeles Alto PA 2400 (2338-2463) 3068 2.49 ± 0.34 2.23 ± 0.07 46 592.75 ± 103.02 4742
Loma de Papeles Bajo PB 2121 (2052-2190) 2743 1.95 ± 0.15 2.58 ± 0.05 56 448 ± 49.25 3584
Pitres PI 1379 (1283-1475) 2671 4.51 ± 0.35 2.85 ± 0.04 64 979.14 ± 84.37 6854
Praillos PRA 1894 (1887-1900) 366 4.61 ± 0.45 2.94 ± 0.09 73 156 ± 23.14 1248
Purche PU 1442 (1387-1496) 2758 5.67 ± 0.77 2.83 ± 0.06 78 1303.88 ± 235.67 10431
Robledal de Dilar DI 1720 (1673-1767) 2725 5.78 ± 0.52 2.93 ± 0.13 82 1402.38 ± 150.25 11219
Sabinas SA 2180 (2177-2184) 289 3.28 ± 0.51 2.42 ± 0.06 50 76 ± 11.82 608
Turbera TU 745 (723-767) 2754 1.4 ± 0.31 1.7 ± 0.09 45 364.14 ± 67.13 2549

sessionInfo()
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

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] kableExtra_1.3.1 here_1.0.1       forcats_0.5.1    stringr_1.4.0   
 [5] dplyr_1.0.6      purrr_0.3.4      readr_1.4.0      tidyr_1.1.3     
 [9] tibble_3.1.2     ggplot2_3.3.5    tidyverse_1.3.1  workflowr_1.7.0 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7        lubridate_1.7.10  getPass_0.2-2     ps_1.5.0         
 [5] assertthat_0.2.1  rprojroot_2.0.2   digest_0.6.27     utf8_1.1.4       
 [9] R6_2.5.1          cellranger_1.1.0  backports_1.2.1   reprex_2.0.0     
[13] evaluate_0.14     highr_0.8         httr_1.4.2        pillar_1.6.1     
[17] rlang_0.4.12      readxl_1.3.1      rstudioapi_0.13   whisker_0.4      
[21] callr_3.7.0       jquerylib_0.1.3   rmarkdown_2.8     webshot_0.5.2    
[25] munsell_0.5.0     broom_0.7.9       compiler_4.0.2    httpuv_1.5.5     
[29] modelr_0.1.8      xfun_0.23         pkgconfig_2.0.3   htmltools_0.5.2  
[33] tidyselect_1.1.1  viridisLite_0.4.0 fansi_0.4.2       crayon_1.4.1     
[37] dbplyr_2.1.1      withr_2.4.1       later_1.1.0.1     grid_4.0.2       
[41] jsonlite_1.7.2    gtable_0.3.0      lifecycle_1.0.1   DBI_1.1.1        
[45] git2r_0.28.0      magrittr_2.0.1    scales_1.1.1.9000 cli_2.5.0        
[49] stringi_1.7.4     fs_1.5.0          promises_1.2.0.1  xml2_1.3.2       
[53] bslib_0.2.4       ellipsis_0.3.2    generics_0.1.0    vctrs_0.3.8      
[57] tools_4.0.2       glue_1.4.2        hms_1.0.0         processx_3.5.1   
[61] fastmap_1.1.0     yaml_2.2.1        colorspace_2.0-2  rvest_1.0.0      
[65] knitr_1.31        haven_2.3.1       sass_0.3.1