--- title: "Introduction to geoidep" author: "Antony Barja" date: "`r format(Sys.time(), '%d %B, %Y')`" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{This package aims to provide R users with a new way of accessing official Peruvian cartographic data on various topics that are managed by the country's Spatial Data Infrastructure.} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", dpi = 300, out.width = "100%" ) ``` ## 1. Introduction This package aims to provide R users with a new way of accessing official Peruvian cartographic data on various topics that are managed by the country's Spatial Data Infrastructure. By offering a new approach to accessing this official data, both from technical-scientific entities and from regional and local governments, it facilitates the automation of processes, thereby optimizing the analysis and use of geospatial information across various fields. **However, this project is still under construction, for more information you can visit the GitHub official repository .** If you want to support this project, you can support me with a coffee for my programming moments.
## 2. Package installation ```r install.packages("geoidep") ``` Also, you can install the development version as follows: ```r install.packages('pak') pak::pkg_install('ambarja/geoidep') ``` ```{r} library(geoidep) ``` ## 3. Basic usage ```{r} providers <- get_data_sources() providers ``` ```{r} layers_available <- get_providers() layers_available ``` ## 4. Download Official Administrative Boundaries by INEI ```{r} # Region boundaries download loreto_prov <- get_provinces(show_progress = FALSE) |> subset(NOMBDEP == 'LORETO') ``` ```{r out.width='100%', out.height=250} library(leaflet) library(sf) loreto_prov |> leaflet() |> addTiles() |> addPolygons() ``` ```{r} # Defined Ubigeo loreto_prov[["ubigeo"]] <- paste0(loreto_prov[["CCDD"]],loreto_prov[["CCPP"]]) ``` ```{r} # The first five rows head(loreto_prov) ``` ## 5. Working with Geobosque data ```{r} my_fun <- function(x){ data <- get_forest_loss_data( layer = 'stock_bosque_perdida_provincia', ubigeo = loreto_prov[["ubigeo"]][x], show_progress = FALSE ) return(data) } historico_list <- lapply(X = 1:nrow(loreto_prov),FUN = my_fun) historico_df <- do.call(rbind.data.frame,historico_list) ``` ```{r} # The first five rows head(historico_df) ``` ## 6. Simple visualization with ggplot ```{r ,fig.align='center'} library(ggplot2) library(dplyr) historico_df |> inner_join(y = loreto_prov,by = "ubigeo") |> ggplot(aes(x = anio,y = perdida)) + geom_point(size = 1) + geom_line() + facet_wrap(NOMBPROV~.,ncol = 3) + theme_minimal(base_size = 5) + labs( title = "Pérdida de bosque histórico del 2001-2023 \npara las provincias de Loreto", caption = "Fuente: Geobosque", x = "", y = "") ```