Load Full Contry Data

WCS camera trap dataset

Author

Diego Lizcano

Published

June 8, 2024

Carguemos algunos paquetes y funciones de ayuda

Code
library(readxl)
library(grateful)

library(sf)
library(mapview)
library(maps)

library(ggTimeSeries)

library(tidyverse)

source("C:/CodigoR/WCS-CameraTrap/R/organiza_datos.R")

Carguemos los datos de un pais

En este caso vamos a usar Ecuador como ejemplo.

Code
########################
### Paises
########################
carpeta <- "C:/CodigoR/WCS-CameraTrap/data/"
paises <- list.files(carpeta,  recursive = FALSE)



Argentina <- data_by_country(country = "Argentina")
Bolivia <- data_by_country(country = "Bolivia")
Brazil <- data_by_country(country = "Brazil")
Colombia <- data_by_country(country = "Colombia")
Ecuador <- data_by_country(country = "Ecuador")
Guatemala <- data_by_country(country = "Guatemala")
Ecuador <- data_by_country(country = "Ecuador")
Paraguay <- data_by_country(country = "Paraguay")
Peru <- data_by_country(country = "Peru")
Venezuela <- data_by_country(country = "Venezuela")

Use la funcion data_by_country para cargar todos los datos de un pais y ver un mapa sencillo e interactivo. Note que podemos usar los datos de cualquier otro pais.

Code

Ecuador <- data_by_country(country = "Ecuador")
#> [1] 1
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 2
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 3
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 4
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 5
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 6
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 7
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 8
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 9
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 10
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 11
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 12
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 13
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 14
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 15
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 16
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 17
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 18
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 19
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 20
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 21
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 22
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] 23
#>  [1] "ID"                                  "Deployment ID"                      
#>  [3] "Point"                               "Longitude Resolution"               
#>  [5] "Latitude Resolution"                 "Camera Deployment Begin Date"       
#>  [7] "Camera Deployment End Date"          "Bait Type"                          
#>  [9] "Bait Description"                    "Feature Type"                       
#> [11] "Feature Type methodology"            "Camera Id"                          
#> [13] "Camera Type"                         "Quiet Period Setting"               
#> [15] "Restriction on Access (Yes/No only)" "Camera Failure Details"             
#> [1] "archivo: ECU-013.xlsxcols: 17"
#> [1] "archivo: ECU-014.xlsxcols: 17"
#> [1] "archivo: ECU-015.xlsxcols: 17"
#> [1] "archivo: ECU-016.xlsxcols: 17"
#> [1] "archivo: ECU-017.xlsxcols: 17"
#> [1] "archivo: ECU-018.xlsxcols: 17"
#> [1] "archivo: ECU-019.xlsxcols: 17"
#> [1] "archivo: ECU-020.xlsxcols: 17"
#> [1] "archivo: ECU-021.xlsxcols: 17"
#> [1] "archivo: ECU-022.xlsxcols: 17"
#> [1] "archivo: ECU-023.xlsxcols: 17"
#> [1] "archivo: ECU_001_17MAR15_Final.xlsxcols: 17"
#> [1] "archivo: ECU_002_17MAR15_Final.xlsxcols: 17"
#> [1] "archivo: ECU_003_17MAR15_Final.xlsxcols: 17"
#> [1] "archivo: ECU_004_17MAR15_Final.xlsxcols: 17"
#> [1] "archivo: ECU_005_17MAR15_Final.xlsxcols: 17"
#> [1] "archivo: ECU_006_17MAR15_Final.xlsxcols: 17"
#> [1] "archivo: ECU_007_17MAR15_Final.xlsxcols: 17"
#> [1] "archivo: ECU_008_17MAR15_Final.xlsxcols: 17"
#> [1] "archivo: ECU_009_17MAR15_Final.xlsxcols: 17"
#> [1] "archivo: ECU_010_17MAR15_Final.xlsxcols: 17"
#> [1] "archivo: ECU_011_17MAR15_Final.xlsxcols: 17"
#> [1] "archivo: ECU_012_17MAR15_Final.xlsxcols: 17"

Country_to_map <- Ecuador |>  distinct(ExcelFile, year, `Deployment ID`, `Longitude Resolution`, `Latitude Resolution`)

projlatlon <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

Country_map <- st_as_sf(x = Country_to_map,                         
                         coords = c("Longitude Resolution", 
                                    "Latitude Resolution"),
                         crs = projlatlon)


mapview(Country_map, zcol = c("year"),  burst = TRUE) # burst = TRUE prouce uniques

Fotos por tipo de camara

Ahora queremos ver las fotos que se han tomado con los diferentes modelos de camaras.

Code
# Creating ggplot graphs 
Ecuador |> mutate(CameraType=`Camera Type`)  |> 
  dplyr::count(CameraType,
               sort = TRUE,
               name = "n_cameraBrand") |> 
  ggplot2::ggplot() + #plotting the camera models most used
  ggplot2::geom_col(ggplot2::aes(x = CameraType,
                                 y = n_cameraBrand)) 

Veamos todas las fotos en un calendario

Code

dtData <- Ecuador  |> as.data.frame() |> 
  mutate(Date_Time=as_date(`Date_Time Captured`)) |> 
    count(Date_Time) |> na.omit()

# base plot
p1 = ggplot_calendar_heatmap(
   dtData,
   'Date_Time',
   'n',
   dayBorderSize = 0.1,
   monthBorderSize = 0.7
)

# adding some formatting
p1 +
   xlab(NULL) +
   ylab(NULL) +
   scale_fill_continuous(low = 'cyan', high = 'red') +
   facet_wrap(~Year, ncol = 2) # number of columns

Fotos con mas de 100 registros por sitios

Seleccionaremos las especies que tienen mas de 100 registros por cada sitio (Deployment ID).

Code
Ecuador |>
  dplyr::distinct(`Deployment ID`, `Genus Species`) |>
  dplyr::count(`Genus Species`, sort = TRUE) |>
  dplyr::filter(n >= 100) |> #change threshold 
  ggplot2::ggplot() +
  ggplot2::geom_col(ggplot2::aes(x = `Genus Species`, y = n)) +
  ggplot2::scale_y_continuous(
    expand = ggplot2::expansion(mult = 0),
    limits = c(0, 1100),
    breaks = seq(0, 1100, by = 100)
  ) +
  ggplot2::labs(x = NULL,
                y = "Locations") +
  ggplot2::coord_flip() 

Code

  ggplot2::theme(
    plot.margin = ggplot2::margin(t = 5,
                                  r = 10,
                                  b = 5,
                                  l = 5,
                                  unit = "pt"),
    axis.text.y = ggtext::element_markdown()
  )
#> List of 2
#>  $ axis.text.y:List of 22
#>   ..$ family        : NULL
#>   ..$ face          : NULL
#>   ..$ size          : NULL
#>   ..$ colour        : NULL
#>   ..$ fill          : NULL
#>   ..$ box.colour    : NULL
#>   ..$ linetype      : NULL
#>   ..$ linewidth     : NULL
#>   ..$ hjust         : NULL
#>   ..$ vjust         : NULL
#>   ..$ halign        : NULL
#>   ..$ valign        : NULL
#>   ..$ angle         : NULL
#>   ..$ lineheight    : NULL
#>   ..$ margin        : NULL
#>   ..$ padding       : NULL
#>   ..$ r             : NULL
#>   ..$ align_widths  : NULL
#>   ..$ align_heights : NULL
#>   ..$ rotate_margins: NULL
#>   ..$ debug         : logi FALSE
#>   ..$ inherit.blank : logi FALSE
#>   ..- attr(*, "class")= chr [1:3] "element_markdown" "element_text" "element"
#>  $ plot.margin: 'margin' num [1:4] 5points 10points 5points 5points
#>   ..- attr(*, "unit")= int 8
#>  - attr(*, "class")= chr [1:2] "theme" "gg"
#>  - attr(*, "complete")= logi FALSE
#>  - attr(*, "validate")= logi TRUE

Y donde estan los Jaguares?

Aca los podemos ver en un mapa, con el tamaño del circulo representando el numero de fotos que se han tomado. Note que podemos cambiar la especie a cualquier otra.

Code
Ecuador_cameras <- st_as_sf(x = Ecuador,                         
                         coords = c("Longitude Resolution", 
                                    "Latitude Resolution"),
                         crs = projlatlon)

jaguars <- Ecuador_cameras |> filter (Ecuador_cameras$`Genus Species`== "Panthera onca") 

jaguars <- jaguars |> mutate(Date_Time=as_date(`Date_Time Captured`)) |> group_by("Deployment ID") |>  count(Date_Time) #|> ungroup() 

mapview(jaguars, cex = "n")

Se ve facil verdad?. Pero en realidad no lo es tanto. Esto ha sido posible gracias a un duro trabajo de varios años de los equipos de WCS de cada pais.

Session info in R.

Code
sessionInfo()
#> R version 4.3.2 (2023-10-31 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19042)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=Spanish_Colombia.utf8  LC_CTYPE=Spanish_Colombia.utf8   
#> [3] LC_MONETARY=Spanish_Colombia.utf8 LC_NUMERIC=C                     
#> [5] LC_TIME=Spanish_Colombia.utf8    
#> 
#> time zone: America/Bogota
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] lubridate_1.9.3    forcats_1.0.0      stringr_1.5.1      dplyr_1.1.4       
#>  [5] purrr_1.0.2        readr_2.1.5        tidyr_1.3.1        tibble_3.2.1      
#>  [9] tidyverse_2.0.0    ggTimeSeries_1.0.2 ggplot2_3.5.1      maps_3.4.2        
#> [13] mapview_2.11.2     sf_1.0-15          grateful_0.2.4     readxl_1.4.3      
#> 
#> loaded via a namespace (and not attached):
#>  [1] tidyselect_1.2.1        farver_2.1.1            fastmap_1.1.1          
#>  [4] leaflet_2.2.1           digest_0.6.34           timechange_0.3.0       
#>  [7] lifecycle_1.0.4         ellipsis_0.3.2          terra_1.7-71           
#> [10] magrittr_2.0.3          compiler_4.3.2          rlang_1.1.3            
#> [13] tools_4.3.2             leafpop_0.1.0           utf8_1.2.4             
#> [16] yaml_2.3.8              data.table_1.15.0       knitr_1.46             
#> [19] labeling_0.4.3          brew_1.0-10             htmlwidgets_1.6.4      
#> [22] sp_2.1-3                classInt_0.4-10         xml2_1.3.6             
#> [25] RColorBrewer_1.1-3      KernSmooth_2.23-22      withr_3.0.0            
#> [28] grid_4.3.2              stats4_4.3.2            fansi_1.0.6            
#> [31] e1071_1.7-14            leafem_0.2.3            colorspace_2.1-0       
#> [34] scales_1.3.0            cli_3.6.2               rmarkdown_2.27         
#> [37] generics_0.1.3          rstudioapi_0.16.0       tzdb_0.4.0             
#> [40] DBI_1.2.2               proxy_0.4-27            s2_1.1.6               
#> [43] cellranger_1.1.0        base64enc_0.1-3         vctrs_0.6.5            
#> [46] jsonlite_1.8.8          hms_1.1.3               systemfonts_1.0.5      
#> [49] crosstalk_1.2.1         jquerylib_0.1.4         units_0.8-5            
#> [52] glue_1.7.0              codetools_0.2-19        leaflet.providers_2.0.0
#> [55] ggtext_0.1.2            stringi_1.8.3           gtable_0.3.4           
#> [58] raster_3.6-26           munsell_0.5.0           pillar_1.9.0           
#> [61] htmltools_0.5.7         satellite_1.0.5         R6_2.5.1               
#> [64] wk_0.9.1                evaluate_0.23           lattice_0.22-5         
#> [67] png_0.1-8               gridtext_0.1.5          class_7.3-22           
#> [70] Rcpp_1.0.12             uuid_1.2-0              svglite_2.1.3          
#> [73] xfun_0.44               pkgconfig_2.0.3

Reuse

Citation

BibTeX citation:
@online{lizcano,
  author = {Lizcano, Diego},
  title = {Load {Full} {Contry} {Data}},
  date = {},
  url = {https://dlizcano.github.io/WCS-CameraTrap/},
  langid = {en}
}
For attribution, please cite this work as:
Lizcano, Diego. n.d. “Load Full Contry Data.” https://dlizcano.github.io/WCS-CameraTrap/.