Last updated: 2021-05-18

Checks: 7 0

Knit directory: booksn_ppm/

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(20210517) 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 1bc6f84. 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
    Ignored:    data/data_raw/

Untracked files:
    Untracked:  analysis/computeMannKendall.Rmd
    Untracked:  analysis/dataNAO.Rmd

Unstaged changes:
    Modified:   analysis/index.Rmd
    Modified:   data/coplas2019.csv
    Modified:   data/coplas2019sn.csv
    Modified:   output/evolucion_temporal_elevacion.pdf
    Modified:   output/evolucion_temporal_especies.pdf
    Modified:   output/evolucion_temporal_reg2005.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/evolucionTemporal.Rmd) and HTML (docs/evolucionTemporal.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 1bc6f84 Antonio J Perez-Luque 2021-05-18 genera temporal evolution using new sp data
html 2a68381 Antonio J Perez-Luque 2021-05-18 Build site.
Rmd 7ffc8f1 Antonio J Perez-Luque 2021-05-18 genera graficos temporal evolution

Evolución temporal por grupo de elevación

library("tidyverse")
library("here")
library("flextable")
library("DT")
library("broom")
coplas2019 <- read_csv(here::here("data/coplas2019sn.csv"))
  • Exploramos la evolución temporal de la infestación (solo los datos de Sierra Nevada) agrupando por especies de pino y por nivel de elevación. Calculamos los valores medios por nivel de elevación y año.
df <- coplas2019 %>% 
  dplyr::select(code, elevF, `1993`:`2019`) %>% 
  pivot_longer(names_to = "year", values_to = "infestacion", `1993`:`2019`) 

df.avg <- 
  df %>% 
  group_by(elevF, year) %>% 
  summarise(mean = mean(infestacion, na.rm=TRUE),
            sd = sd(infestacion, na.rm=TRUE),
            se = sd/sqrt(length(infestacion)), 
            size = length(infestacion)) %>% 
  mutate(year.date = lubridate::ymd(year, truncated = 2L),
         elevF_label = recode(elevF, "0verylow" = "< 600 m",
                           "1low" = "600 - 1200 m",
                           "2medium" = "1200 - 1700 m",
                           "3high" = "> 1700 m"))


colores_elevacion <- c(
  "0verylow" = "#d7191c",
  "1low" = "#fdae61",
  "2medium" = "#abd9e9",
  "3high" = "#2c7bb6"
)

colores_elevacion_label <- c(
  "< 600 m" = "#d7191c",
  "600 - 1200 m" = "#fdae61",
  "1200 - 1700 m" = "#abd9e9",
  "> 1700 m" = "#2c7bb6"
)


evol_temporal_elevacion <- 
df.avg %>% 
  ggplot(aes(x=year.date, y=mean, group=elevF_label, color = elevF_label, fill=elevF_label)) +
  scale_color_manual(values = colores_elevacion_label) + 
  theme_bw() +
  theme(
    panel.grid = element_blank(),
    legend.title = element_blank(), 
    legend.position = c(0.5,.9), 
    legend.background = element_blank()) + 
  scale_x_date(date_breaks = "2 years", date_labels = "%Y") +
  xlab("Year") + ylab("Mean defoliation") + ylim(0, NA) +
  geom_point(size=1.5) + 
  geom_line() +
  geom_errorbar(aes(ymin=mean - se, ymax=mean + se), width = .1) +
  guides(colour = guide_legend(nrow = 2))

Version Author Date
2a68381 Antonio J Perez-Luque 2021-05-18
null device 
          1 

Evolución temporal por especie

Número de parcelas por especie

DT::datatable(coplas2019 %>% group_by(sp_abrev) %>% count()) 
  • Seleccionamos P. nigra, P. halpensis, P. sylvestris, P. pinaster
dfspraw <- coplas2019 %>% filter(especie %in% c("P. nigra", "P. halpensis", "P. sylvestris","P. pinaster")) 

dfsp <- dfspraw %>% 
  dplyr::select(code, especie, elev_mean, `1993`:`2019`) %>% 
  pivot_longer(names_to = "year", values_to = "infestacion", `1993`:`2019`) 

dfsp.avg <- 
  dfsp %>% 
  group_by(especie, year) %>% 
  summarise(mean = mean(infestacion, na.rm=TRUE),
            sd = sd(infestacion, na.rm=TRUE),
            se = sd/sqrt(length(infestacion)), 
            size = length(infestacion)) %>% 
  mutate(year.date = lubridate::ymd(year, truncated = 2L)) 

colores_pinos <- c("P. halpensis" = "#809c13", 
                   "P. nigra" = "#45492a", 
                   "P. pinaster" = "gray", 
                   "P. sylvestris" = "#ffa64d")

evol_temporal_especies <- 
  dfsp.avg %>% 
  ggplot(aes(x=year.date, y=mean, group=especie, color = especie, fill=especie)) +
  scale_color_manual(values = colores_pinos) +
  theme_bw() +
  theme(
    panel.grid = element_blank(), 
    legend.title = element_blank(), 
    legend.position = c(0.5,.9), 
    legend.background = element_blank()
  ) + 
  scale_x_date(date_breaks = "2 years", date_labels = "%Y") +
  xlab("Year") + ylab("Mean defoliation") + ylim(0, NA) +
    geom_point(size=1.5) + 
  geom_line() +
  geom_errorbar(aes(ymin=mean - se, ymax=mean + se), width = .1) +
  guides(colour = guide_legend(nrow = 2))

Version Author Date
2a68381 Antonio J Perez-Luque 2021-05-18
null device 
          1 

Tendencia últimos años

  • Explorar la tendendia desde 2005 (solo fines exploratorios). Sabemos que este modelo estadísticamte es inválido.

Version Author Date
2a68381 Antonio J Perez-Luque 2021-05-18
null device 
          1 
ft1 <- do(df2005 %>% group_by(especie), 
   glance(lm(mean~year, data=.))) %>%
  dplyr::select(especie, r.squared, p.value) %>% 
  mutate_if(is.numeric, round, 4) %>% 
  flextable() 
ft1 
ft2 <- do(df2005 %>% group_by(especie), 
   tidy(lm(mean~year, data=.))) %>% 
  mutate_if(is.numeric, round, 3) %>% 
  flextable() 
ft2

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] broom_0.7.4     DT_0.17         flextable_0.6.3 here_1.0.1     
 [5] forcats_0.5.1   stringr_1.4.0   dplyr_1.0.4     purrr_0.3.4    
 [9] readr_1.4.0     tidyr_1.1.2     tibble_3.0.6    ggplot2_3.3.3  
[13] tidyverse_1.3.0 workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] httr_1.4.2        sass_0.3.1        jsonlite_1.7.2    splines_4.0.2    
 [5] modelr_0.1.8      bslib_0.2.4       assertthat_0.2.1  highr_0.8        
 [9] cellranger_1.1.0  yaml_2.2.1        gdtools_0.2.3     pillar_1.4.7     
[13] backports_1.2.1   lattice_0.20-41   glue_1.4.2        uuid_0.1-4       
[17] digest_0.6.27     promises_1.2.0.1  rvest_0.3.6       colorspace_2.0-0 
[21] Matrix_1.3-2      htmltools_0.5.1.1 httpuv_1.5.5      pkgconfig_2.0.3  
[25] haven_2.3.1       scales_1.1.1      whisker_0.4       later_1.1.0.1    
[29] officer_0.3.16    git2r_0.28.0      mgcv_1.8-33       generics_0.1.0   
[33] farver_2.0.3      ellipsis_0.3.1    withr_2.4.1       cli_2.3.0        
[37] magrittr_2.0.1    crayon_1.4.1      readxl_1.3.1      evaluate_0.14    
[41] fs_1.5.0          nlme_3.1-152      xml2_1.3.2        tools_4.0.2      
[45] data.table_1.13.6 hms_1.0.0         lifecycle_1.0.0   munsell_0.5.0    
[49] reprex_1.0.0      zip_2.1.1         compiler_4.0.2    jquerylib_0.1.3  
[53] systemfonts_1.0.0 rlang_0.4.10      grid_4.0.2        rstudioapi_0.13  
[57] htmlwidgets_1.5.3 crosstalk_1.1.1   base64enc_0.1-3   labeling_0.4.2   
[61] rmarkdown_2.6.6   gtable_0.3.0      DBI_1.1.1         R6_2.5.0         
[65] lubridate_1.7.10  knitr_1.31        rprojroot_2.0.2   stringi_1.5.3    
[69] Rcpp_1.0.6        vctrs_0.3.6       dbplyr_2.1.0      tidyselect_1.1.0 
[73] xfun_0.20