An Introduction to Tidy R Spatial Packages: Incorporating Historic Sociodemographic Data from the US Census and Visualizing Geographic Distributions
This repository contains an introductory demo to using spatial packages in R, prepared for the R Medicine 2024 conference. The demo will walk you through downloading Census data, merging in health data, exploring the data with summary statistics, and creating geographic maps to explore geographic distributions of the variables.
We have organized relevant files in the following folders:
code
: Code for the demodata
: Health data needed for the demoimages
: Supportive images for the demo
We used two primary data sources for the following features in this demo:
-
U.S. American Community Survey, 2017-2021 5-year estimates: sociodeconomic variables
- Request a U.S. Census API key here
-
U.S. Centers for Disease Control and Prevention PLACES, 2023: CHD prevalence
You will need the following software, R packages, and data to complete the demo.
- Download the following software:
- Run the following code in R to install the following packages:
install.packages(c('tidyverse','tidycensus','readr','sf','ggspatial','patchwork'), dependencies = TRUE)
- We used the following versions of software and packages:
- Software:
- R: 4.2.2 ("Innocent and trusting")
- RStudio: 2024.04.1+748 ("Chocolate Cosmos")
- Packages:
tidyverse
: 1.3.2tidycensus
: 1.3.2readr
: 2.1.3sf
: 1.0.9ggspatial
: 1.1.9patchwork
: 1.2.0
- U.S. Centers for Disease Control and Prevention PLACES 2020
- Download here.
- U.S. American Community Survey, 5-year estimates from 2017-2021
- To download the data, refer to our code:
code/demo-rspatial.Rmd
- To download the data, refer to our code:
Below are steps to clone this repository to your local device with RStudio. Please refer to this link for more information about using git in RStudio.
- On top this page, click on
Code
and copy the link to this git repository (starts with https://github.com/...). - Open RStudio.
- In RStudio, click on
File
→New Project...
→Version Control
→Git
. - Under "Repository URL", paste the link of the git repository.
- Under "Project directory name", name your project directory.
- Under "Create project as subdirectory of:", select the folder in which you would like your project directory to be located.
- Click on
Create Project
when you are done to clone your repository!