Urban Ipixuna: subset food insecurity items


Filter Ipixuna urban data for “spatial item factor analysis paper”.

Load required libraries and data

rm(list = ls())
library(day2day)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
library(ggplot2)

path_main <- git_path()
path_data <- file.path(path_main, "data")
path_raw <- file.path(path_data, "raw")
path_processed <- file.path(path_data, "processed")

# food insecurity data
fidata <- st_read(file.path(path_processed, "fi-items.gpkg"))
#> Reading layer `fi-items' from data source 
#>   `/home/rstudio/documents/projects/food-insecurity-mapping/data/processed/fi-items.gpkg' 
#>   using driver `GPKG'
#> Simple feature collection with 1109 features and 36 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -72.05338 ymin: -7.56604 xmax: -57.40498 ymax: -2.44214
#> Geodetic CRS:  WGS 84
# census level data
(load(file.path(path_raw, "data-amazonia", "census_03_ipixuna_urb.RData")))
#> [1] "data_ipix_urb"

Subset Ipixuna data

fi_ipixuna <- fidata |>
    filter(tolower(municipality) == "ipixuna", !is_rural) |>
    arrange(registro)
fi_ipixuna_path <- file.path(path_processed, "fi-items-ipixuna-urban.gpkg")
st_write(fi_ipixuna, fi_ipixuna_path, delete_dsn = TRUE)
#> Deleting source `/home/rstudio/documents/projects/food-insecurity-mapping/data/processed/fi-items-ipixuna-urban.gpkg' using driver `GPKG'
#> Writing layer `fi-items-ipixuna-urban' to data source 
#>   `/home/rstudio/documents/projects/food-insecurity-mapping/data/processed/fi-items-ipixuna-urban.gpkg' using driver `GPKG'
#> Writing 200 features with 36 fields and geometry type Point.

Visualization

# update crs format with current way
st_crs(data_ipix_urb) = st_crs(data_ipix_urb)
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
# sf::st_crs(fi_ipixuna)
ggplot(data_ipix_urb) +
    geom_sf(fill = NA, color = 2) +
    geom_sf(data = st_jitter(fi_ipixuna, factor = 0.02)) +
    ggtitle("Jittered locations of households (Urban Ipixuna).")

Time to execute the task

Only useful when executed with Rscript.

proc.time()
#>    user  system elapsed 
#>   1.729   0.384   1.802