knitr::opts_chunk$set(echo = TRUE)

To explore the Biodiversity role in the Carbon - Soil compactation correlation found by Diego N.

The initial idea: To sample Carbon, Bettles, Ants and Spiders in a 100-150 m grid in Cubarral (Meta) to model the spatially splicit relatinship between covariates, incorporating remote sensing info.

Draft Idea

draft

draft

Idea Evolution

The initial idea changed to sample just ants and dung bettles in a 80 m grid.

library (tidyverse) # Data handling
library (raster)  # grids, rasters
library (rgeos) # coord transform
library (rgdal) # coord transform
library (ggmap) # visualization
library (lubridate) # date managemgemt
library (readxl) # read excel data
library (sf) # vector maps in R
library (sp) # vector old fashon maps in R
library (mapview) # see maps in web

Read Data

For dung bettles and ants

path <- "C:/Users/diego.lizcano/Box Sync/CodigoR/Carbon-Biodiv/Data"
beetle_data <- read_excel(paste(path,"/TNC_Escarabajo_Carbono_June_2018.xlsx", sep=""), 
    sheet = "Base_Escarabajos")

beetle_data <- beetle_data %>% group_by(Punto) %>% 
  mutate (Richness = n_distinct(Especie))  # New column richness

beetle_data$LongDD <- beetle_data$LonDD * (-1)

ants_data <- read_excel(paste(path,"/TNC_Escarabajo_Carbono_June_2018.xlsx", sep=""), 
    sheet = "Base_Hormigas")

ants_data <- ants_data %>% group_by(Punto) %>% 
  mutate (Richness = n_distinct(Especie))

ants_data$LongDD <- ants_data$LonDD * (-1)

Make sf

beetle_data_sf = st_as_sf(beetle_data, coords = c("LongDD", "LatDD"), crs = "+proj=longlat +datum=WGS84")

 # put coords

ants_data_sf = st_as_sf(ants_data, coords = c("LongDD", "LatDD"), crs = "+proj=longlat +datum=WGS84")

Plot Beetle Data

Beetle Richness

# 
mapview(beetle_data_sf, zcol = "Richness", 
        col.regions = sf.colors(12),
        alpha = 0.1, 
        legend = TRUE, 
        map.types = "Esri.WorldImagery")

Beetle Abundance

# 
mapview(beetle_data_sf, zcol = "Abundancia", 
        col.regions = sf.colors(12),
        alpha = 0.1, 
        legend = TRUE, 
        map.types = "Esri.WorldImagery")
# 
p <- ggplot(beetle_data, aes(x=Cobertura, y=Richness)) + 
  geom_boxplot() 
p

Plot Ant Data

Ant Richness

# 
mapview(ants_data_sf, zcol = "Richness", 
        col.regions = sf.colors(12),
        alpha = 0.1, 
        legend = TRUE, 
        map.types = "Esri.WorldImagery")

Ant Abundance

mapview(ants_data_sf, zcol = "Abundancia", 
         col.regions = sf.colors(15),
         alpha = 0.1, 
         legend = TRUE, 
         map.types = "Esri.WorldImagery")
# 
q <- ggplot(ants_data, aes(x=Cobertura, y=Richness)) + 
  geom_boxplot() 
q

Session Info

Details and pakages used

print(sessionInfo(), locale = FALSE)
## R version 3.4.0 (2017-04-21)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 16299)
## 
## Matrix products: default
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] mapview_2.4.0      sf_0.6-3           readxl_1.1.0      
##  [4] lubridate_1.7.4    ggmap_2.6.1        rgdal_1.3-2       
##  [7] rgeos_0.3-28       raster_2.6-7       sp_1.3-1          
## [10] forcats_0.3.0      stringr_1.3.1      dplyr_0.7.5       
## [13] purrr_0.2.5        readr_1.1.1        tidyr_0.8.1       
## [16] tibble_1.4.2       ggplot2_2.2.1.9000 tidyverse_1.2.1   
## 
## loaded via a namespace (and not attached):
##  [1] nlme_3.1-137       satellite_1.0.1    webshot_0.5.0     
##  [4] httr_1.3.1         rprojroot_1.3-2    tools_3.4.0       
##  [7] backports_1.1.2    R6_2.2.2           spData_0.2.9.0    
## [10] DBI_1.0.0          lazyeval_0.2.1     colorspace_1.3-2  
## [13] withr_2.1.2        tidyselect_0.2.4   mnormt_1.5-5      
## [16] leaflet_2.0.1      compiler_3.4.0     cli_1.0.0         
## [19] rvest_0.3.2        xml2_1.2.0         labeling_0.3      
## [22] scales_0.5.0       classInt_0.2-3     psych_1.8.4       
## [25] digest_0.6.15      foreign_0.8-67     rmarkdown_1.10    
## [28] R.utils_2.6.0      base64enc_0.1-3    jpeg_0.1-8        
## [31] pkgconfig_2.0.1    htmltools_0.3.6    maps_3.3.0        
## [34] htmlwidgets_1.2    rlang_0.2.1        rstudioapi_0.7    
## [37] shiny_1.1.0        bindr_0.1.1        jsonlite_1.5      
## [40] crosstalk_1.0.0    R.oo_1.22.0        magrittr_1.5      
## [43] geosphere_1.5-7    RPostgreSQL_0.6-2  Rcpp_0.12.17      
## [46] munsell_0.5.0      proto_1.0.0        R.methodsS3_1.7.1 
## [49] stringi_1.2.3      yaml_2.1.19        plyr_1.8.4        
## [52] grid_3.4.0         parallel_3.4.0     promises_1.0.1    
## [55] crayon_1.3.4       lattice_0.20-35    haven_1.1.1       
## [58] mapproj_1.2.6      hms_0.4.2          knitr_1.20        
## [61] pillar_1.2.3       rjson_0.2.20       gdalUtils_2.0.1.14
## [64] stats4_3.4.0       reshape2_1.4.3     codetools_0.2-15  
## [67] glue_1.2.0         evaluate_0.10.1    modelr_0.1.2      
## [70] png_0.1-7          httpuv_1.4.4.1     foreach_1.4.4     
## [73] RgoogleMaps_1.4.2  cellranger_1.1.0   gtable_0.2.0      
## [76] assertthat_0.2.0   mime_0.5           xtable_1.8-2      
## [79] broom_0.4.4        e1071_1.6-8        later_0.7.3       
## [82] viridisLite_0.3.0  class_7.3-14       iterators_1.0.9   
## [85] units_0.6-0        bindrcpp_0.2.2

Cited Literature