Spatial Data
Spatial Data Visualizations
This section contains more advanced data visualization techniques, and is entirely optional. Many students have indicated an interested in visualizing spatial data. Feel free to skip this section if this does not apply to your interests.
Spatial data is often used in epidemiology and public health research. Some key applications include identifying clusters and disease hotspots, looking at environmental or geographical relationships with health outcomes, and in investigating geographic inequities in health outcomes or services.
Chloropleth maps use colors and shading to show a hierarchical relationship across geographic boundaries (ie. income, population density, mortality rate, etc.) and help to visualize spatial patterns.
To work with spatial data in R, first there are some necessary packages to install. In general, the maps package is sufficient in visualizing a basic chloropleth map, which will be used for demonstration in this section. Other packages list below are also commonly used to map spatial data, such as the sf package, which allows for more complex spatial data manipulation and analysis.
An Introduction to GIS using R is also avaliable from the Univeristy of Toronto Map and Data Library here
Suppose we want to look at the PFAS exposures across the United States. First, let’s load the map of the United States using the map_data() function in the maps R package.
Then, we need to join our PFAS data to the spatial data. Recall that a shared column between the datasets is required to perform the join, and both datasets must be aggregated at the same geographical unit.
To use ggplot2 to create maps, we usually set up the geographical location (longitude and latitude) using x and y, insert the numerical values using the fill parameter and use the geom_polygon() option. Gradient color schemes are controlled by scale_fill_gradient(), they are great for displaying chloropleth maps, as the darker and lighter shades visually communicate the data in an intuitive way.
This section does not provide an exhaustive tutorial on spatial data anaylsis, but rather an introduction. If you are interested in learning in more depth about spatial data visualizations, the University of Toronto Map & Data Library has detailed applications of the sf package here.