Opioid Environment Toolkit for R-Spatial
Preface
This toolkit provides an introduction to GIS and spatial analysis for health applications that will allow researchers, analysts, and practitioners to support their communities with better data analytics and visualization services.
We introduce basic spatial analytic functionalities using open source tools, mainly in R, using applied examples for visualizing, mapping, and understanding the community environment. As a project of the Justice Community Overdose Innovation network, applications covered consider the opioid and overdose risk environment.
The original toolkit version was published in 2020. This version was updated in 2025 and will continue to be expanded through the end of 2029.
What You’ll Need
In addition to this workbook, you’ll need a working instance of R and the data. You can also clone the Github repository that hosts this workbook to get direct access to all the working code, data, and additional items.
Software Basics
We assume a basic knowledge of R and coding languages for most sections. For most of the tutorials in this toolkit, you’ll need to have R and RStudio downloaded and installed on your system. You should be able to install packages, know how to find the address to a folder on your computer system, and have very basic familiarity with R. If you are new to R, we recommend the following intro-level tutorials provided through installation guides. You can also refer to this R for Social Scientists tutorial developed by Data Carpentry for a refresher.
We will work with following libraries, so please be sure to install:
tidyverseordplyrsftmaptidygeocodertidycensus
To install a package in R, input install.packages("dplyr") in your console. You generally only need to install a library once, but you’ll call it every time you work with a new R session.
We recommend setting up your working directory as soon as you can! Create a new folder called “data” to put all the data you’ve downloaded for the workshop.
There are differing spatial ecosystems in R. We use the sf ecosystem that is compatible with the tidyverse. If you need to work between these two R spatial ecosystems, see this guide for a translation of sp to sf commands.
Acknowledgements
This research was supported by the National Institutes of Health through the NIH HEAL Initiative under award number 1U2CDA050098-01 and 5UM1DA050098-03. The contents of this publication are solely the responsibility of the authors and do not necessarily represent the official views of the NIH, the NIH HEAL Initiative, or the participating sites.