Last updated: 2021-05-07

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 366c184. 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/passerine_ab.csv
    Untracked:  data/passerine_abbrev.csv
    Untracked:  output/abundance_time/passerine_abtotal.csv
    Untracked:  output/abundance_time/passerine_abtotal_compare.csv
    Untracked:  output/diversity/alfa_diversity.csv
    Untracked:  output/diversity/richness.csv
    Untracked:  output/turnover/

Unstaged changes:
    Deleted:    analysis/temporal-beta-diveristy.Rmd
    Modified:   code/computeTBI.R
    Modified:   data/birds.csv
    Deleted:    data/data_raw/~$Aves_SN_meses_reproduccion.xlsx
    Modified:   data/passerine.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/plot_betadiversity.pdf
    Modified:   output/diversity/diversity_habitat.pdf
    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/trend-analysis.Rmd) and HTML (docs/trend-analysis.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 725547c Antonio J Perez-Luque 2021-05-05 Build site.
Rmd 55b3a47 Antonio J Perez-Luque 2021-05-05 add mankendall anañysis

Introduction

knitr::opts_chunk$set(echo = TRUE, 
                      warning = FALSE, 
                      message = FALSE)
library("tidyverse")
library("here")
library("rtrim")
library("trend")
library("DT")
  • 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 = sp.abb) %>% 
  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)) 

Explore Abundances as index

  • For each species we compute the abundance index, i.e. relative abundance comparing with initial values (\(ab_{index} = abundance_{time_{i}} / abundance_{time_{0}}\))

  • Data was exported as (data/passerine_ab.csv)

compute_abindex <- function(x){
  ab.base <- x %>% filter(year == min(x$year)) %>% pull(ab_avg)
  out <- x %>% mutate(ab.index = ab_avg/ab.base) %>% dplyr::select(year,ab.index)
  return(out)
}

cumbres <- passerine.ab %>% 
  filter(habitat == "cumbres") 
cumbres.index <- cumbres %>% 
  group_by(sp) %>% group_modify(
    ~ {compute_abindex(.x)})
cumbres <-cumbres %>%  inner_join(cumbres.index)


enebral <- passerine.ab %>% 
  filter(habitat == "enebral") 
enebral.index <- enebral %>% 
  group_by(sp) %>% group_modify(
    ~ {compute_abindex(.x)})
enebral <- enebral %>%  inner_join(enebral.index)

robledal <- passerine.ab %>% 
  filter(habitat == "robledal") 
robledal.index <- robledal %>% 
  group_by(sp) %>% group_modify(
    ~ {compute_abindex(.x)})
robledal <- robledal %>%  inner_join(robledal.index)

passerine.abindex <- bind_rows(cumbres, enebral, robledal) %>% 
  inner_join(passerine_abbreviations, by = c("sp" = "sp.abb"))

write_csv(passerine.abindex, here::here("data/passerine_ab.csv"))
bird_theme <- 
  ggplot2::theme_bw() + 
  ggplot2::theme(
    panel.grid.minor = element_blank(),
    strip.background = element_blank()
  )
# Generate functions to plot abundances and abundance index 
plotabundances <- function(df, myhabitat, selected_especies){
  df %>% 
  filter(habitat == myhabitat) %>% 
  filter(stringr::str_detect(especie, selected_especies)) %>%
  ggplot(aes(x=as.factor(year), y=ab_avg)) + 
  geom_errorbar(aes(ymin = ab_avg - se, 
                    ymax = ab_avg + se),
                width = 0.2) +
  geom_point() +
  geom_point(aes(x=as.factor(year), y=ab.index), color = "red", shape=15) + 
  geom_hline(yintercept = 1, colour="red", linetype = "dashed") + 
  facet_wrap(~especie) + 
  geom_line(aes(x=as.factor(year), y=ab.index, group=1), colour = "red") +
  ylab("abundance (ind / 10ha)") + xlab("") + 
  bird_theme + 
  ggtitle(myhabitat)
} 

plotabindex <- function(df, myhabitat, selected_especies){
  df %>% 
  filter(habitat == myhabitat) %>% 
  filter(stringr::str_detect(especie, selected_especies)) %>%
  ggplot(aes(x=as.factor(year), y=ab.index)) + 
  geom_point(color = "red", shape=15) + 
  geom_hline(yintercept = 1, colour="red", linetype = "dashed") + 
  facet_wrap(~especie) + 
  geom_line(aes(x=as.factor(year), y=ab.index, group=1), colour = "red") +
  ylab("abundance (ind / 10ha)") + xlab("") + 
  bird_theme + 
  ggtitle(myhabitat)
} 
sp_cumbres <- "Card|Oena|Phoeni|collaris"
sp_enebral <- "Alauda|Anthus|cannabina|Embe|Oena|Phoeni|collaris|conspici|Troglo"
sp_robledal <- "Aeg|cannabina|Certhia|Cyanis|Erith|Fringi|Garrulus|Lullula|Parus|Peripares|Phoeni|bonelli|Regulus|rubicola|serinus|Sitta|atricapilla|cantillans|merula|visci|Troglo"

# enebral rubicola
# robledal Lopho
plotabundances(df = passerine.abindex, 
           myhabitat = "cumbres",
           selected_especies = sp_cumbres)

plotabundances(df = passerine.abindex, 
           myhabitat = "enebral",
           selected_especies = sp_enebral)

plotabundances(df = passerine.abindex, 
           myhabitat = "robledal",
           selected_especies = sp_robledal)
plotabindex(df = passerine.abindex, 
           myhabitat = "cumbres",
           selected_especies = sp_cumbres)

Version Author Date
725547c Antonio J Perez-Luque 2021-05-05
plotabindex(df = passerine.abindex, 
           myhabitat = "enebral",
           selected_especies = sp_enebral)

Version Author Date
725547c Antonio J Perez-Luque 2021-05-05
plotabindex(df = passerine.abindex, 
           myhabitat = "robledal",
           selected_especies = sp_robledal)

Version Author Date
725547c Antonio J Perez-Luque 2021-05-05