knitr::opts_chunk$set(echo = TRUE)

This script create the site persistence parts tables 5 and 6 It uses a dataset where Mencia and Aceitillar data have been combined.

Libraries

library(reshape2)
library(here)

Load data

Load annual Captures data with Mencia AND Aceitillar combined

filename <- "site_persist.RData"
load(here::here("data",filename))
ls()

Subset by focal species

focal.mig <- c("OVEN","BAWW","COYE","AMRE","CMWA",
               "BTBW","PAWA","PRAW")

focal.res <- c("HILC" # formerly HLCU
,"STOF"
,"RLTH"
,"NOMO"
,"GTGT"   # formerly GRWA
,"BANA"
,"BCPT"
,"YFGR"
,"BFGR"
,"GABU")

focals <- c(focal.mig,focal.res)
i.focal <- which(site_persist$spp.code %in% focals)
site_persist.foc <- site_persist[i.focal,]

Set order for tables

replicate order from tables in oridingal MS

site_persist.foc$spp.code <- factor(site_persist.foc$spp.code,
                             levels = focals)

Order sites by age

site_persist.foc$site <- factor(site_persist.foc$site,
                      levels = c("La Cueva",
                                 "La Caoba",
                                 "Morelia",
                                 "El Corral",
                                 "Aceitillar"))

Cast for site persistent

#sample size
sp.cast.n <- dcast(data= site_persist.foc[,],
      formula = spp.code + stat ~ site,
      value.var = "site",
      fun.aggregate = length)

#siter persisten individuals
sp.cast.persist <- dcast(data= site_persist.foc[,],
      formula = spp.code + stat ~ site+persist,
      value.var = "site",
      fun.aggregate = length)
#isolate focal columns
j <- grep("_P",names(sp.cast.persist))
sp.cast.persist[,j]

sp.cast.persist2 <- round(sp.cast.persist[,j]/sp.cast.n[,-c(1:2)],2)

Paste together

sp.cast.persist3 <- sp.cast.persist2

sp.cast.persist3$`La Cueva_P` <- paste(sp.cast.persist3$`La Cueva_P`," (",sp.cast.n$`La Cueva`,")", sep = "")

sp.cast.persist3$`La Caoba_P` <- paste(sp.cast.persist3$`La Caoba_P`," (",sp.cast.n$`La Caoba`,")", sep = "")

sp.cast.persist3$Morelia_P <- paste(sp.cast.persist3$`Morelia_P`," (",sp.cast.n$Morelia,")", sep = "")

sp.cast.persist3$`El Corral_P` <- paste(sp.cast.persist3$`El Corral_P`," (",sp.cast.n$`El Corral`,")", sep = "")
table5_6_site_persist <- data.frame(spp.code = sp.cast.persist[,1],
                                    sp.cast.persist3)

Save table

write.csv(table5_6_site_persist, 
          file = "./tables/temp_tables_5_6_site_persist.csv",
          row.names = F)


brouwern/DRmencia documentation built on May 6, 2019, 12:24 p.m.