knitr::opts_chunk$set(echo = TRUE)
In this vignette, we show how we prepared the ZCTA shape data that can be downloaded using the get_data()
function specifying the data = "zctashapefile"
. In case you want to use different files you can follow some of these preprocessing steps.
First, we load the packages that we will need for completing this task.
library(disperseR) library(data.table) library(tidyverse)
In case you have not yet created your project folder use the following command.
disperseR::create_dirs()
We use use ZCTA shapefiles from the US census website US census website. It is important to note that this website sometimes fails and the download should be postponed.
file <- file.path(zcta_dir, 'cb_2017_us_zcta510_500k.zip') url <- 'ftp://ftp2.census.gov/geo/tiger/GENZ2017/shp/cb_2017_us_zcta510_500k.zip' if(!file.exists(file)){ download.file(url = url, destfile = file) unzip(file, exdir = zcta_dir) }
You can can load these files into your R session as follows.
zcta <- file.path(zcta_dir, 'cb_2017_us_zcta510_500k.shp') # define path zcta <- raster::shapefile(x = zcta)
It is recommended to transform the ZCTA shapefile to a known projection to maintain consistency throughout the allocation process. Lat-lon projections are preferred, such as the North American Albers Equal Area Conic:
p4s <- "+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m" zcta <- sp::spTransform(x = zcta, CRSobj = p4s)
The ZCTA shape file should now be available in your environment.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.