Question

Are the NDVI frequency distributions different between the whole geography and the tourism predios?

Set up analysis

Load libraries and set some options.

codigo R
library(sf) # Simple Features for R
library(terra) # Spatial Data Analysis
library(mapview) # Interactive Viewing of Spatial Data in R
library(grateful) # Facilitate Citation of R Packages 
library (ggplot2) # easy graphs in R

library(dplyr) # filter sf

options(scipen=99999)
options(max.print=99999)
options(stringsAsFactors=F)

Load Rasters (.tif)

codigo R
NDVI_full_montes <- rast("C:/Users/usuario/Downloads/Indice_NDVI_GeografiaMontesMaria_2023.tif")
# plot(NDVI_full_montes)

Load predios (.shp)

codigo R
predios <- st_read("C:/CodigoR/Municipios_DN/shp/predios/PrediosDNA.shp")

Reading layer PrediosDNA' from data sourceC:_DN.shp’ using driver `ESRI Shapefile’ Simple feature collection with 491 features and 20 fields Geometry type: MULTIPOLYGON Dimension: XY Bounding box: xmin: -81.61475 ymin: 0.2220508 xmax: -72.04356 ymax: 11.35795 Geodetic CRS: WGS 84

View the maps

codigo R
slectedpredios <- predios |>  filter(GEOGRAFIA=="MONTES DE MARIA")
a1 <- aggregate(NDVI_full_montes, 10) #agregate to easy view

|———|———|———|———|

codigo R
mapview(a1) + mapview(slectedpredios)

Extract NDVI for predios

codigo R

NDVI_predios <- terra::extract(NDVI_full_montes, predios, xy=TRUE)

Histogram full geography

codigo R
# convert raster to dataframe
full_montes_df <- as.data.frame(NDVI_full_montes, xy = TRUE) # this works with Raster* objects as well

p<-ggplot(full_montes_df, aes(x=NDVI)) + 
  geom_histogram(color="black", fill="white", bins =100)
p

Histogram for predios

codigo R

q<-ggplot(NDVI_predios, aes(x=NDVI)) + 
  geom_histogram(color="black", fill="white", bins =100)
q

Package Citation

codigo R
pkgs <- cite_packages(output = "paragraph", out.dir = ".")
knitr::kable(pkgs)
x
We used R version 4.3.2 (R Core Team 2023) and the following R packages: knitr v. 1.46 (Xie 2014, 2015, 2024), mapview v. 2.11.2 (Appelhans et al. 2023), rmarkdown v. 2.27 (Xie, Allaire, and Grolemund 2018; Xie, Dervieux, and Riederer 2020; Allaire et al. 2024), sf v. 1.0.15 (Pebesma 2018; Pebesma and Bivand 2023), terra v. 1.7.71 (Hijmans 2024), tidyverse v. 2.0.0 (Wickham et al. 2019).
codigo R
# pkgs

Información de la sesión en R.

codigo R
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] dplyr_1.1.4    ggplot2_3.5.1  grateful_0.2.4 mapview_2.11.2 terra_1.7-71  
#> [6] sf_1.0-15     
#> 
#> loaded via a namespace (and not attached):
#>  [1] gtable_0.3.4            xfun_0.44               raster_3.6-26          
#>  [4] htmlwidgets_1.6.4       lattice_0.22-5          leaflet.providers_2.0.0
#>  [7] vctrs_0.6.5             tools_4.3.2             crosstalk_1.2.1        
#> [10] generics_0.1.3          stats4_4.3.2            parallel_4.3.2         
#> [13] tibble_3.2.1            proxy_0.4-27            fansi_1.0.6            
#> [16] pkgconfig_2.0.3         KernSmooth_2.23-22      satellite_1.0.5        
#> [19] RColorBrewer_1.1-3      uuid_1.2-0              leaflet_2.2.1          
#> [22] lifecycle_1.0.4         compiler_4.3.2          farver_2.1.1           
#> [25] munsell_0.5.0           codetools_0.2-19        stars_0.6-4            
#> [28] htmltools_0.5.7         class_7.3-22            yaml_2.3.8             
#> [31] pillar_1.9.0            jquerylib_0.1.4         ellipsis_0.3.2         
#> [34] classInt_0.4-10         lwgeom_0.2-13           wk_0.9.1               
#> [37] abind_1.4-5             brew_1.0-10             tidyselect_1.2.1       
#> [40] digest_0.6.34           labeling_0.4.3          fastmap_1.1.1          
#> [43] grid_4.3.2              colorspace_2.1-0        cli_3.6.2              
#> [46] magrittr_2.0.3          base64enc_0.1-3         utf8_1.2.4             
#> [49] leafem_0.2.3            e1071_1.7-14            withr_3.0.0            
#> [52] scales_1.3.0            sp_2.1-3                rmarkdown_2.27         
#> [55] png_0.1-8               evaluate_0.23           knitr_1.46             
#> [58] s2_1.1.6                rlang_1.1.3             Rcpp_1.0.12            
#> [61] leafpop_0.1.0           glue_1.7.0              DBI_1.2.2              
#> [64] renv_1.0.3              svglite_2.1.3           rstudioapi_0.16.0      
#> [67] jsonlite_1.8.8          R6_2.5.1                systemfonts_1.0.5      
#> [70] units_0.8-5

References

Allaire, JJ, Yihui Xie, Christophe Dervieux, Jonathan McPherson, Javier Luraschi, Kevin Ushey, Aron Atkins, et al. 2024. rmarkdown: Dynamic Documents for r. https://github.com/rstudio/rmarkdown.
Appelhans, Tim, Florian Detsch, Christoph Reudenbach, and Stefan Woellauer. 2023. mapview: Interactive Viewing of Spatial Data in r. https://CRAN.R-project.org/package=mapview.
Hijmans, Robert J. 2024. terra: Spatial Data Analysis. https://CRAN.R-project.org/package=terra.
Pebesma, Edzer. 2018. Simple Features for R: Standardized Support for Spatial Vector Data.” The R Journal 10 (1): 439–46. https://doi.org/10.32614/RJ-2018-009.
Pebesma, Edzer, and Roger Bivand. 2023. Spatial Data Science: With applications in R. Chapman and Hall/CRC. https://doi.org/10.1201/9780429459016.
R Core Team. 2023. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al. 2019. “Welcome to the tidyverse.” Journal of Open Source Software 4 (43): 1686. https://doi.org/10.21105/joss.01686.
Xie, Yihui. 2014. knitr: A Comprehensive Tool for Reproducible Research in R.” In Implementing Reproducible Computational Research, edited by Victoria Stodden, Friedrich Leisch, and Roger D. Peng. Chapman; Hall/CRC.
———. 2015. Dynamic Documents with R and Knitr. 2nd ed. Boca Raton, Florida: Chapman; Hall/CRC. https://yihui.org/knitr/.
———. 2024. knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.
Xie, Yihui, Christophe Dervieux, and Emily Riederer. 2020. R Markdown Cookbook. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown-cookbook.

Citation

BibTeX citation:
@online{untitled,
  author = {},
  url = {https://dlizcano.github.io/NDVIhist/},
  langid = {en}
}
For attribution, please cite this work as:
n.d. https://dlizcano.github.io/NDVIhist/.