Spatial Analysis and Mapping with R

3 Data

As an example we will map census tracts in Maryland and Baltimore City with limited access to COVID-19 vaccination sites using open access datasets.

3.1 Data

The following datasets were retrieved from different open access sources on April 4, 2021:

  1. Food Access Research Atlas Data (Data Download 2015) (Excel Workbook format [.xlsx])
  2. Census tract boundaries (ESRI shapefile collection [.zip])
  3. List of COVID-19 vaccination sites in Maryland, with coordinates (comma separated values file, [.csv])
  4. Maryland Physical Boundaries – County Boundaries (ESRI shapefile collection [.zip])

Access to Data

The datasets were archived in a zip compressed file ( that can be downloaded at SpatialAnalysisData. The link will connect you to a cloud storage service (MEGA, and ask you to download the file. By accessing the cloud storage service and downloading the file/data you agree to the terms of service of MEGA and to the terms of use of the code and data.

 Data Retrieval

  1. Create a directory called data in your R project folder.
  2. Click on the SpatialAnalysisData link.
  3. Click on Download and save the file in the data directory. A zip compressed archive file (; about 81.5 MB large) will be downloaded.
  4. Unzip the archive file with the following R command:
destfile <- "data/"

unzip(destfile, exdir = "data/")

If you get a warning message, such as

In unzip(destfile, exdir = "data/") : error 1 in extracting from zip file

then the file may have not been downloaded into your directory.


  • if you have a typo in the destfile,
  • if you are in the correct working directory (with the command getwd()), or
  • if the zip archive file is in the data directory of your working directory.

The latter can be checked with the R command file.exists():


If the outcome is [1] "FALSE" then the file is missing. Find the file and move it into the data directory.

Once successful, you should have the following files in your data directory:

  • FoodAccess2015.xlsx
  • gz_2010_24_140_00_500k.dbf
  • gz_2010_24_140_00_500k.prj
  • gz_2010_24_140_00_500k.shp
  • gz_2010_24_140_00_500k.shx
  • gz_2010_24_140_00_500k.xml
  • Maryland_Physical_Boundaries_-_County_Boundaries_(Detailed).cpg
  • Maryland_Physical_Boundaries_-_County_Boundaries_(Detailed).csv
  • Maryland_Physical_Boundaries_-_County_Boundaries_(Detailed).dbf
  • Maryland_Physical_Boundaries_-_County_Boundaries_(Detailed).prj
  • Maryland_Physical_Boundaries_-_County_Boundaries_(Detailed).shp
  • Maryland_Physical_Boundaries_-_County_Boundaries_(Detailed).shx
  • Maryland_Physical_Boundaries_-_County_Boundaries_(Detailed).xml
  • MD_counties_CT.dbf
  • MD_counties_CT.prj
  • MD_counties_CT.shp
  • MD_counties_CT.shx
  • MD_Covid19_VacSites_2021-04-04.csv

3.2 Data Sources and Description

Food Access Research Atlas Data (2015 Dataset)

In 2008 the U.S. Congress directed the USDA to assess the extend of areas with limited access to fresh food (U.S. Department of Agriculture, 2009). Subsequently, the USDA Economic Research Service (USDA-ERS) developed a mapping tool called “the Food Desert Locator” (Ver Ploeg et al., 2011). The Food Desert Locator allows to identify census tracts that qualify as food deserts [as defined by USDA, Treasury, and HHS (Ver Ploeg et al., 2011)].

We are using this dataset as it lists (among more than 140 parameters) low-income and low-vehicle access census tracts.

The data is compiled into an Excel workbook (download size approx. 75 Mb). The workbook has three sheets, Read me, Variable Lookup, and Food Access Research Atlas. The latter contains the data aggregated based on data from the 2010 census.

Definitions and data sources can be accessed at

Source: USDA Economic Research Service (USDA-ERS), available at
Source URL:, retrieved on Apr 4, 2021

Census Tracts

Food Atlas data is based on census tracts of the 2010 census. Census tracts are (relatively stable) statistical subdivisions of counties that ideally have 4,000 people (range: 1,200–8,000 people) (U.S. Census Bureau, 2019). To map, census tracts polygons are required.

Source: Census Tracts for Maryland, United States Census Bureau, Cartographic Boundary Files – Shapefile, available at
URL (Maryland):, retrieved on Apr 4, 2021

Census tract polygons are stored in an ESRI shapefile collection as a zip archive file. The zip file contains 5 files, a shapefile (.shp), 3 necessary auxiliary files (.dbf, .prj, .shx), and an additional .xml file. The .xml file is not necessary for spatial analysis.

List of COVID-19 Vaccination Sites

A list of COVID-19 vaccination sites in Maryland was retrieved from the Maryland Department of Health Coronavirus website (

Source: All Maryland Vaccination Sites,
URL (.csv):, retrieved on Apr 4, 2021
Credit: Maryland Department of Health COVID-19 Testing Task Force

The dataset was slightly modified for educational purposes. An additional variable (column)—Location—was added and variables rearranged. The Location variable contains GPS coordinates of the vaccination sites in a (latitude, longitude) format. This format is often encountered in datasets that provide GPS information in tabular form.

Maryland County Boundaries

Shapefile collection containing boundaries of Maryland counties. Based on unified census tract boundaries (source of the original data: Census Tracts).


U.S. Census Bureau. (2019). Glossary. Retrieved April 5, 2021, from

U.S. Department of Agriculture. (2009). Access to affordable and nutritious food: Measuring and understanding food deserts and their consequences.

Ver Ploeg, M., Nulph, D., & Williams, R. (2011). Mapping food deserts in the United States. Retrieved April 5, 2021, from


Icon for the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

Spatial Analysis and Mapping with R: A Short Tutorial Copyright © 2021 by Wolf T. Pecher is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, except where otherwise noted.