diff --git a/DESCRIPTION b/DESCRIPTION index fba301f..3d5a731 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: sfDR Title: Simple Features for Dominican Republic Administrative Boundaries -Version: 0.1.3 +Version: 0.1.4 Authors@R: c(person(given = "Daniel E.", family = "de la Rosa", diff --git a/R/data.R b/R/data.R index 9217bb7..0aee531 100644 --- a/R/data.R +++ b/R/data.R @@ -1,9 +1,9 @@ #' Percentage distribution by provinces of remittances received by the Dominican Republic #' -#' @format ## `remesas_provincias` +#' @format ## `remittance_by_province` #' \describe{ #' \item{province}{Full name of the province} #' \item{percentage}{Percentage of the total remittances received in 2010} #' } #' @source -'remesas_provincias' +'remittance_by_province' diff --git a/README.Rmd b/README.Rmd index 4048e0f..b29aa2e 100644 --- a/README.Rmd +++ b/README.Rmd @@ -61,7 +61,7 @@ The original simple features dataset only includes the PROV_ID variable. Additio ```{r} datos <- DR_PROV_SF |> - left_join(remesas_provincias, by = join_by('PROV_NAME' == 'province')) + left_join(remittance_by_province, by = join_by('PROV_NAME' == 'province')) datos %>% sf::st_drop_geometry() @@ -87,7 +87,7 @@ library(ggplot2) DR_PROV %>% sf::st_as_sf() %>% left_join(dr_province) %>% - left_join(remesas_provincias, by = join_by('PROV_NAME' == 'province')) %>% + left_join(remittance_by_province, by = join_by('PROV_NAME' == 'province')) %>% ggplot() + geom_sf(aes(fill = percentage)) + theme_void() diff --git a/README.html b/README.html new file mode 100644 index 0000000..73128b3 --- /dev/null +++ b/README.html @@ -0,0 +1,761 @@ + + + + + + + + + + + + + + + + + + + + + +

sfDR +sfDR website

+ + +

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. +Lifecycle: experimental r-universe

+ + +

The goal of sfDR is to provide a comprehensive suite of simple +feature (sf) objects for the administrative boundaries of the Dominican +Republic, facilitating geospatial analysis and mapping.

+

Installation

+

You can install the development version of sfDR from r-universe +with:

+
if (!require('sfDR')) install.packages('sfDR', repos = c('https://adatar-do.r-universe.dev'))
+if (!require('dplyr')) install.packages('dplyr')
+if (!require('ggplot2')) install.packages('ggplot2')
+#> Loading required package: ggplot2
+#> Warning: package 'ggplot2' was built under R version 4.3.1
+

Example

+

This is a basic example showing how to use sfDR to plot a Dominican +Republic province map:

+
library(sfDR)
+library(dplyr)
+
+DR_PROV_SF <- sf::st_as_sf(DR_PROV)
+
+plot(DR_PROV_SF)
+ + +

Suppose you have a dataset showing the percentage distribution of +remittances received in each province of the Dominican Republic for a +specific year. To visualize this data using a graph with sfDR, you first +need to combine the metadata with the simple features.

+
DR_PROV_SF <- DR_PROV_SF |>
+  left_join(dr_province, by = join_by(PROV_ID))
+
+DR_PROV_SF %>% 
+  sf::st_drop_geometry()
+#>    PROV_ID PROV_CODE                  PROV_NAME
+#> 1       21        SC             San Cristóbal
+#> 2       14       MTS   María Trinidad Sánchez
+#> 3       17       PER                    Peravia
+#> 4       20       SAM                    Samaná
+#> 5       18        PP               Puerto Plata
+#> 6       11        LA              La Altagracia
+#> 7       07        EP               Elías Piña
+#> 8       10       IND              Independencia
+#> 9       16       PED                 Pedernales
+#> 10      03       BAH                    Baoruco
+#> 11      03       BAH                   Bahoruco
+#> 12      04       BAR                   Barahona
+#> 13      26       SRO        Santiago Rodríguez
+#> 14      27       VAL                   Valverde
+#> 15      19       HMI           Hermanas Mirabal
+#> 16      19       SAL                    Salcedo
+#> 17      24       SRA          Sánchez Ramírez
+#> 18      13        LV                    La Vega
+#> 19      28        MN            Monseñor Nouel
+#> 20      31       SJO          San José de Ocoa
+#> 21      22        SJ                   San Juan
+#> 22      22        SJ     San Juan de la Maguana
+#> 23      02       AZU                       Azua
+#> 24      25       SAN                   Santiago
+#> 25      25       SAN Santiago de los Caballeros
+#> 26      06       DUA                     Duarte
+#> 27      09       ESP                  Espaillat
+#> 28      29        MP                Monte Plata
+#> 29      30       HMA                 Hato Mayor
+#> 30      12        LR                  La Romana
+#> 31      23       SPM      San Pedro de Macorís
+#> 32      08        ES                   El Seibo
+#> 33      08        ES                   El Seybo
+#> 34      01        DN          Distrito Nacional
+#> 35      05       DAJ                   Dajabón
+#> 36      32        SD              Santo Domingo
+#> 37      15        MC               Monte Cristi
+

The original simple features dataset only includes the PROV_ID +variable. Additional variables are incorporated through the dr_province +object.

+
 datos <- DR_PROV_SF |>
+  left_join(remittance_by_province, by = join_by('PROV_NAME' == 'province'))
+
+datos %>% 
+  sf::st_drop_geometry()
+#>    PROV_ID PROV_CODE                  PROV_NAME  percentage
+#> 1       21        SC             San Cristóbal          NA
+#> 2       14       MTS   María Trinidad Sánchez          NA
+#> 3       17       PER                    Peravia 0.005948295
+#> 4       20       SAM                    Samaná          NA
+#> 5       18        PP               Puerto Plata 0.018996422
+#> 6       11        LA              La Altagracia          NA
+#> 7       07        EP               Elías Piña          NA
+#> 8       10       IND              Independencia          NA
+#> 9       16       PED                 Pedernales          NA
+#> 10      03       BAH                    Baoruco          NA
+#> 11      03       BAH                   Bahoruco          NA
+#> 12      04       BAR                   Barahona          NA
+#> 13      26       SRO        Santiago Rodríguez          NA
+#> 14      27       VAL                   Valverde 0.004422258
+#> 15      19       HMI           Hermanas Mirabal          NA
+#> 16      19       SAL                    Salcedo          NA
+#> 17      24       SRA          Sánchez Ramírez          NA
+#> 18      13        LV                    La Vega 0.014144396
+#> 19      28        MN            Monseñor Nouel          NA
+#> 20      31       SJO          San José de Ocoa          NA
+#> 21      22        SJ                   San Juan          NA
+#> 22      22        SJ     San Juan de la Maguana          NA
+#> 23      02       AZU                       Azua          NA
+#> 24      25       SAN                   Santiago 0.039947667
+#> 25      25       SAN Santiago de los Caballeros          NA
+#> 26      06       DUA                     Duarte 0.008876070
+#> 27      09       ESP                  Espaillat 0.004489833
+#> 28      29        MP                Monte Plata          NA
+#> 29      30       HMA                 Hato Mayor          NA
+#> 30      12        LR                  La Romana 0.008441885
+#> 31      23       SPM      San Pedro de Macorís          NA
+#> 32      08        ES                   El Seibo          NA
+#> 33      08        ES                   El Seybo          NA
+#> 34      01        DN          Distrito Nacional 0.090322521
+#> 35      05       DAJ                   Dajabón          NA
+#> 36      32        SD              Santo Domingo 0.098682428
+#> 37      15        MC               Monte Cristi          NA
+

It’s important to note that non-ASCII characters can become corrupted +when stored in the package, which may affect the merging of the data +sets.

+
+

We recommend cleaning any errors before performing the merge. We will +soon release another package with functions designed to facilitate this +process.

+
+
datos |>
+  select(percentage) %>% 
+  plot()
+ + +

To get the desired graph, just apply the plot function to your +data.

+

Next, we show how to achieve a similar result using ggplot2. This +serves to demonstrate how to create maps with both libraries and to +highlight the simplicity of the process by integrating everything in one +step.

+
library(ggplot2)
+
+DR_PROV %>%
+  sf::st_as_sf() %>% 
+  left_join(dr_province) %>% 
+  left_join(remittance_by_province, by = join_by('PROV_NAME' == 'province')) %>% 
+  ggplot() +
+  geom_sf(aes(fill = percentage)) +
+  theme_void()
+#> Joining with `by = join_by(PROV_ID)`
+ + + + diff --git a/README.md b/README.md index df11f46..9b8150f 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ You can install the development version of sfDR from r-universe with: if (!require('sfDR')) install.packages('sfDR', repos = c('https://adatar-do.r-universe.dev')) if (!require('dplyr')) install.packages('dplyr') if (!require('ggplot2')) install.packages('ggplot2') +#> Loading required package: ggplot2 +#> Warning: package 'ggplot2' was built under R version 4.3.1 ``` ## Example @@ -99,7 +101,7 @@ Additional variables are incorporated through the dr_province object. ``` r datos <- DR_PROV_SF |> - left_join(remesas_provincias, by = join_by('PROV_NAME' == 'province')) + left_join(remittance_by_province, by = join_by('PROV_NAME' == 'province')) datos %>% sf::st_drop_geometry() @@ -171,7 +173,7 @@ library(ggplot2) DR_PROV %>% sf::st_as_sf() %>% left_join(dr_province) %>% - left_join(remesas_provincias, by = join_by('PROV_NAME' == 'province')) %>% + left_join(remittance_by_province, by = join_by('PROV_NAME' == 'province')) %>% ggplot() + geom_sf(aes(fill = percentage)) + theme_void() diff --git a/data-raw/remesas_provincias.R b/data-raw/remesas_provincias.R index 9bc818e..49dcd58 100644 --- a/data-raw/remesas_provincias.R +++ b/data-raw/remesas_provincias.R @@ -1,11 +1,11 @@ library(dplyr) library(tidyr) -remesas_provincias <- readxl::read_excel('data-raw/Remesas_PR.xlsx', skip = 6) %>% +remittance_by_province <- readxl::read_excel('data-raw/Remesas_PR.xlsx', skip = 6) %>% select(1:2) %>% drop_na() %>% setNames(c('province', 'percentage')) %>% filter(percentage != 1) -usethis::use_data(remesas_provincias, overwrite = TRUE) +usethis::use_data(remittance_by_province, overwrite = TRUE) diff --git a/data/remittance_by_province.rda b/data/remittance_by_province.rda new file mode 100644 index 0000000..419ca9d Binary files /dev/null and b/data/remittance_by_province.rda differ diff --git a/man/figures/README-unnamed-chunk-7-1.png b/man/figures/README-unnamed-chunk-7-1.png index a960968..83c1b37 100644 Binary files a/man/figures/README-unnamed-chunk-7-1.png and b/man/figures/README-unnamed-chunk-7-1.png differ diff --git a/man/remesas_provincias.Rd b/man/remittance_by_province.Rd similarity index 80% rename from man/remesas_provincias.Rd rename to man/remittance_by_province.Rd index 37efa44..e47c00e 100644 --- a/man/remesas_provincias.Rd +++ b/man/remittance_by_province.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/data.R \docType{data} -\name{remesas_provincias} -\alias{remesas_provincias} +\name{remittance_by_province} +\alias{remittance_by_province} \title{Percentage distribution by provinces of remittances received by the Dominican Republic} \format{ -\subsection{\code{remesas_provincias}}{ +\subsection{\code{remittance_by_province}}{ \describe{ \item{province}{Full name of the province} @@ -17,7 +17,7 @@ \url{https://www.bancentral.gov.do/a/d/2532-sector-externo} } \usage{ -remesas_provincias +remittance_by_province } \description{ Percentage distribution by provinces of remittances received by the Dominican Republic