Lab 1: Plotting

How labs work

Labs are done with your group during class and are meant to be mostly finished in the class period. You may use AI to ask questions or debug, but not to write your code for you—the point is for your group to think it through together. At the end, add a one-line note saying whether and how you used AI.

Overview

In this lab you will practice building and polishing plots with ggplot2 using a clean data set we provide, so you can focus entirely on the visualization. We will explore the classic question of whether economic development and democracy go together (Lipset’s “modernization” hypothesis). The data are a country-year panel with a democracy score (polyarchy), GDP per capita (gdp_pc), region, and year.

library(tidyverse)
library(scales)

# A tidy data set is provided for you on the course site.
dem_data <- read_csv("https://raw.githubusercontent.com/eteitelbaum/dataviz/main/modules/data/dem_women.csv")
glimpse(dem_data)
Rows: 6,025
Columns: 9
$ country      <chr> "Mexico", "Mexico", "Mexico", "Mexico", "Mexico", "Mexico…
$ vdem_ctry_id <dbl> 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, …
$ iso3c        <chr> "MEX", "MEX", "MEX", "MEX", "MEX", "MEX", "MEX", "MEX", "…
$ year         <dbl> 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 199…
$ polyarchy    <dbl> 0.393, 0.415, 0.441, 0.455, 0.474, 0.493, 0.515, 0.559, 0…
$ gdp_pc       <dbl> 11.389, 11.635, 11.883, 11.983, 12.043, 11.742, 12.059, 1…
$ region       <chr> "Latin America", "Latin America", "Latin America", "Latin…
$ women_rep    <dbl> NA, NA, NA, NA, NA, NA, NA, 14.20, 17.40, 18.20, 16.00, 1…
$ flfp         <dbl> NA, 34.26, 35.02, 35.86, 36.39, 37.63, 37.70, 39.66, 39.3…

Step 1: A scatter plot of development vs. democracy (35 pts)

Using a single recent year of the data, make a scatter plot with GDP per capita on the x-axis and the democracy score on the y-axis, colored by region. Put the x-axis on a log scale and format it as dollars with the scales package, add a viridis color map, clear labels, and a theme. Then add a linear trend line with geom_smooth(method = "lm").

Step 2: A line chart over time (35 pts)

Pick four or five countries from different regions and make a line chart of the democracy score over time, mapping country to color. Add clear labels and a caption, a colorblind-friendly palette, and a theme. Add one annotation—for example a vertical line marking an important date—using annotate() or geom_vline().

Step 3: Interpret (30 pts)

In a few sentences of markdown text (not in a code chunk), interpret your two charts. Does the evidence support the idea that development and democracy go together? Point to an interesting exception if you see one.

AI note: (one line on whether/how your group used AI)