Last updated: 2022-02-04

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 ac1f648. 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/

Unstaged changes:
    Modified:   analysis/index.Rmd
    Modified:   figs/correlation_env_variables.pdf
    Modified:   figs/correlation_env_variables_numbers.pdf
    Modified:   figs/dendrograma_env.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/plot_variables_elevation.Rmd) and HTML (docs/plot_variables_elevation.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 c814af8 ajpelu 2022-01-18 fix error link ambientales
html 30a1406 ajpelu 2022-01-18 update
html 8d38806 ajpelu 2021-12-30 Build site.
Rmd 533f0a9 ajpelu 2021-12-30 add plot variables and outputs

Objetivo

  • Crear un plot de variación de los parámetros con la elevación
library(tidyverse)
library(here)
library(ggpubr)
library(ggrepel)
  • Read data
denraw <- read_csv(here::here("data/densidad_by_year.csv")) 
divraw <- read_csv(here::here("data/diversidad_by_year.csv")) 
riqraw <- read_csv(here::here("data/riqueza_by_year.csv"))

Plot Densidad

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

plot_density <- densidad_avg %>%
  ggplot(aes(x=elev, y = mean, label=site)) +
  geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs"), colour="gray", alpha=.3) +
  # geom_smooth(method="loess", span=.5) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se)) +
  geom_point(size=2, shape=21, fill="white") +
  theme_bw() +
  theme(
    panel.grid = element_blank()
  ) +
  ylab("Abundance (n ind / 100 m)") +
  xlab("Elevation") +
  geom_text_repel()

plot_density

Version Author Date
30a1406 ajpelu 2022-01-18
8d38806 ajpelu 2021-12-30

Plot Diversidad

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

plot_diversity <- diversidad_avg %>%
  ggplot(aes(x=elev, y = mean, label = site)) +
  geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs"), colour="gray", alpha=.3) +
  # geom_smooth() +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se)) +
  geom_point(size=2, shape=21, fill="white") +
  theme_bw() +
  theme(
    panel.grid = element_blank()
  ) +
  ylab("Diversity (Shannon index)") +
  xlab("Elevation") +
  geom_text_repel()

plot_diversity

Version Author Date
30a1406 ajpelu 2022-01-18
8d38806 ajpelu 2021-12-30

Plot Riqueza

richness_avg <- riqraw %>%
  group_by(transecto, site, elev) %>%
  summarise(mean = mean(riq, na.rm = TRUE),
            sd = sd(riq, na.rm = TRUE),
            se = sd/sqrt(n()))

plot_richness <- richness_avg %>%
  ggplot(aes(x=elev, y = mean, label = site)) +
  geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs"), colour="gray", alpha=.3) +
  # geom_smooth() +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se)) +
  geom_point(size=2, shape=21, fill="white") +
  theme_bw() +
  theme(
    panel.grid = element_blank()
  ) +
  ylab("Richness (species number") +
  xlab("Elevation") +
  geom_text_repel()

plot_richness

Version Author Date
30a1406 ajpelu 2022-01-18
8d38806 ajpelu 2021-12-30

Todas las variables juntas

p <- bind_rows(
  richness_avg %>% mutate(variable = "riq"),
  diversidad_avg %>% mutate(variable = "div"),
  densidad_avg %>% mutate(variable = "den"))
  
  
mylabel <- c(
  den = "Abundance (n ind / 100 m)",
  div = "Diversity (Shannon index)",
  riq = "Richness (species number)")


plot_variables <- p %>%
  ggplot(aes(x=elev, y = mean, label = site)) +
  geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs"), colour="gray", alpha=.3) +
  # geom_smooth() +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se)) +
  geom_point(size=2, shape=21, fill="white") +
  theme_bw() +
  theme(
    panel.grid = element_blank(),
    strip.text = element_text(face = "bold"),
    strip.background = element_rect(fill="white")
  ) + geom_text_repel() + 
  facet_wrap(~variable, ncol=1, scales = "free_y",
             labeller = labeller(variable = mylabel),
             strip.position="top") + 
  xlab("Elevation") + ylab("") 
ggsave(here::here("figs/plot_variables_elevation.pdf"),
       device = "pdf",
       width = 5, height = 7.5)
plot_variables

Version Author Date
30a1406 ajpelu 2022-01-18
8d38806 ajpelu 2021-12-30
dev.off()
null device 
          1 
ggsave(plot= plot_variables,
       here::here("figs/plot_variables_elevation.png"),
       device = "png",
       dpi = 300,
       width = 5, height = 7.5)

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

loaded via a namespace (and not attached):
 [1] nlme_3.1-152      fs_1.5.0          lubridate_1.7.10  httr_1.4.2       
 [5] rprojroot_2.0.2   tools_4.0.2       backports_1.2.1   bslib_0.2.4      
 [9] utf8_1.1.4        R6_2.5.1          DBI_1.1.1         mgcv_1.8-33      
[13] colorspace_2.0-2  withr_2.4.1       tidyselect_1.1.1  processx_3.5.1   
[17] curl_4.3          compiler_4.0.2    git2r_0.28.0      textshaping_0.3.2
[21] cli_2.5.0         rvest_1.0.0       xml2_1.3.2        labeling_0.4.2   
[25] sass_0.3.1        scales_1.1.1.9000 callr_3.7.0       systemfonts_1.0.0
[29] digest_0.6.27     foreign_0.8-81    rmarkdown_2.8     rio_0.5.16       
[33] pkgconfig_2.0.3   htmltools_0.5.2   highr_0.8         dbplyr_2.1.1     
[37] fastmap_1.1.0     rlang_0.4.12      readxl_1.3.1      rstudioapi_0.13  
[41] farver_2.1.0      jquerylib_0.1.3   generics_0.1.0    jsonlite_1.7.2   
[45] zip_2.1.1         car_3.0-10        magrittr_2.0.1    Matrix_1.3-2     
[49] Rcpp_1.0.7        munsell_0.5.0     fansi_0.4.2       abind_1.4-5      
[53] lifecycle_1.0.1   stringi_1.7.4     whisker_0.4       yaml_2.2.1       
[57] carData_3.0-4     grid_4.0.2        promises_1.2.0.1  crayon_1.4.1     
[61] lattice_0.20-41   haven_2.3.1       splines_4.0.2     hms_1.0.0        
[65] knitr_1.31        ps_1.5.0          pillar_1.6.1      ggsignif_0.6.0   
[69] reprex_2.0.0      glue_1.4.2        evaluate_0.14     getPass_0.2-2    
[73] data.table_1.14.0 modelr_0.1.8      vctrs_0.3.8       httpuv_1.5.5     
[77] cellranger_1.1.0  gtable_0.3.0      assertthat_0.2.1  xfun_0.23        
[81] openxlsx_4.2.3    broom_0.7.9       rstatix_0.6.0     later_1.1.0.1    
[85] ragg_1.1.1        ellipsis_0.3.2