Week 2
Visualizing spatial data with {ggplot2}
weeks
Summary
Learn to make plots and maps using the {ggplot}
package. Visualization is a key method in learning how to explore, tidy, and interpret data.
Overview
This week is all about making plots and maps using the {ggplot}
package. Learning to visualize data is a great place for start learning how to exploring data analytically and understanding the value of tidy data when working with R.
Key Objectives
- Introduce the concept of a “pipe” (
%>%
or|>
) and how and when to use it - Introduce the concept of the “grammar of graphics”
- Practice plotting and mapping data with
{ggplot2}
- Practice mapping data with
{mapview}
Key Skills
- Using keyboard shortcuts in RStudio
- Creating plots using
ggplot()
,aes()
, andgeom_()
functions - Creating static maps using
geom_sf()
andcoord_sf()
- Creating interactive maps using
mapview()
- Using
theme_
functions to customize the appearance of a plot - Using
labs()
to add labels to a plot
Prepare
Required readings
- Ch. 2 Data visualization in Hadley Wickham, Garrett Grolemund, and Mine Çetinkaya-Rundel R for Data Science: Import, Tidy, Transform, Visualize, and Model Data, 2nd edition. (Sebastopol, CA: O’Reilly Media, 2023), https://r4ds.hadley.nz/.
- Ch. 6 Workflow: scripts and projects in Wickham, Grolemund, and Çetinkaya-Rundel R for Data Science.
- Ch. 6 Maps in Hadley Wickham, Danielle Navarro, and Thomas Lin Pedersen Ggplot2: Elegant Graphics for Data Analysis, 3rd (WIP)., Use R! (Springer, 2023), https://ggplot2-book.org/index.html.
Optional readings
- Elliot Bentley “The Web as Medium for Data Visualization,” in The Data Journalism Handbook: Towards A Critical Data Practice, ed. Liliana Bounegru and Jonathan Gray, 2nd ed. (Amsterdam University Press, 2021), 138–142, doi:10.2307/j.ctv1qr6smr.29.
- ggplot2 workshop part 1 and part 2 with Thomas Lin Pedersen, 2020
- Ch. 9 Mapping in Robin Lovelace, Jakub Nowosad, and Jannes Muenchow Geocomputation with R, 2nd ed. (CRC Press, 2025), https://r.geocompx.org.
Participate
Practice
🛠️️ Exercise 02