Assignment 07: Spatial analysis in R
Tip
I highly recommend checking out the channel ▶️ Milos Makes Maps on YouTube and his 😺 GitHub for tutorials on spatial data analysis and mapping in R!
🎯 Learning Objectives
By the end of this assignment, you will be able to:
- Understand and work with spatial data in R using the
sfpackage. - Read and manipulate shapefiles.
- Create choropleth maps to visualize spatial patterns.
- Combine tabular data with spatial data for thematic mapping.
- Customize map aesthetics, including projections and color schemes.
- Document your spatial analysis process in a Quarto report.
📂 Datasets
For this assignment, you will need two types of data:
- Spatial Data: A shapefile with the administrative boundaries of Ukraine’s oblasts.
- Tabular Data: A dataset containing some variable to visualize across the oblasts.
Note
You can use any other country or region if you prefer, but make sure to adjust the instructions accordingly.
For the tabular data, you have three options. Choose one:
- Option A: Air Raid Sirens Data: Use the dataset on air raid sirens in Ukraine from this source. You will need to aggregate the data by oblast.
- Option B: State Statistics Service of Ukraine: Find a dataset of your choice on the State Statistics Service of Ukraine.
- Option C: Your Own Data: Find or create your own dataset with data for each of Ukraine’s oblasts.
📝 Tasks
⚙️ Step 1: Set Up Your Project
- Create a new Quarto document (
.qmd) for your assignment. - Load the necessary libraries:
sf,tidyverse, and any others you might need. - Download the shapefile of Ukraine’s oblasts and place it in a
datasubdirectory within your project.
🔄 Step 2: Load and Prepare Data
- Load the Spatial Data: Read the shapefile into R using
sf::read_sf(). - Load the Tabular Data: Load the tabular dataset you chose.
- Data Cleaning and Preparation:
- Clean both datasets as needed. Pay special attention to the names of the oblasts to ensure they are consistent between the two datasets for a successful join.
- If you chose the air raid sirens data, you will need to aggregate it to the oblast level (e.g., total number of alerts, total duration).
- Join the Datasets: Perform a join (e.g.,
left_join()) to merge your tabular data with the spatial data based on the oblast names.
📊 Step 3: Create a Choropleth Map
- Create a Basic Map: Use
ggplot2andgeom_sf()to create a basic choropleth map of Ukraine, where the fill color of each oblast represents the value of the variable you are analyzing. - Customize the Map:
- Add a title, subtitle, and caption.
- Customize the color scale using
scale_fill_*(). - Experiment with different map projections using
coord_sf(). - Adjust the theme for a cleaner look (
theme_void()is a good starting point).
- Interpret Your Map: Write a brief interpretation of the patterns you observe in your map. What does the map reveal about your chosen variable?
💡 Bonus Challenge (Optional)
- Create an additional map that visualizes a different variable or uses a different mapping technique (e.g., a point map, a line map).
- Add labels to the oblasts on your map.
- Find and add major cities as points on your map.
📤 Submission
Submit a Quarto report (.qmd and the rendered PDF or HTML document) that includes:
- A description of your chosen dataset.
- All the code for loading, cleaning, and joining the data.
- The final choropleth map.
- Your interpretation of the map.
If you render to HTML, please publish your report on Quarto Pub or GitHub Pages and include the link in your submission.