Individuals are nested in social networks
Provinces are surrounded by other provinces
Country-level outcomes are often a result of negotiations with other countries:
Homophily---similarity in outcomes is endogenous, units are similar because they self-select into the same outcome (e.g., partisan geo-sorting)
Common exposure---similarity in outcomes is driven by an exogenous factor that affects nearby units (the effect of earthquakes on housing prices)
Diffusion---nearby units affect each other through learning, imitation, etc (e.g., policy diffusion)
Source: van Weezel S. "On climate and conflict: Precipitation decline and communal conflict in Ethiopia and Kenya." Journal of Peace Research. 2019;56(4):514--528.
Source: Chyzh, Olga V. and R. Urbatsch. 2021. "Bean Counters: The Effect of Soy Tariffs on Change in Republican Vote Share Between the 2016 and 2018 Elections."Journal of Politics 83 (1): 415--419.
Latitude/longitude points for all map boundaries
Need to know to which boundary/state lat/long points belong
Need to know the order to connect points within each group
library(tidyverse)library(mapproj)library(maps)library(mapdata)states <- map_data("state")head(states)
## long lat group order region subregion## 1 -87.46201 30.38968 1 1 alabama <NA>## 2 -87.48493 30.37249 1 2 alabama <NA>## 3 -87.52503 30.37249 1 3 alabama <NA>## 4 -87.53076 30.33239 1 4 alabama <NA>## 5 -87.57087 30.32665 1 5 alabama <NA>## 6 -87.58806 30.32665 1 6 alabama <NA>
library(ggplot2)ggplot() + geom_path(data=states, aes(x=long, y=lat, group=group),color="black", size=.5)
#Set theme options:theme_set(theme_grey() + theme(axis.text=element_blank(), axis.ticks=element_blank(), axis.title.x=element_blank(), axis.title.y=element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.border = element_blank(), panel.background = element_blank(), legend.position="none"))ggplot() + geom_path(data=states, aes(x=long, y=lat, group=group),color="black", size=.5)+ coord_map()
ggplot() + geom_polygon(data=states, aes(x=long, y=lat, group=group),color="black", size=.5)+ coord_map()
Add other geographic information (e.g., counties) by adding geometric layers to the plot
Add non-geographic information by altering the fill color for each state
Use geom = "polygon" to treat states as solid shapes to add color
Incorporate numeric information using color shade or intensity
Incorporate categorical informaion using color hue
If a categorical variable is assigned as the fill color then ggplot will assign different hues for each category.
Let’s load in a state regions dataset:
statereg<- read.csv("./data/statereg.csv")head(statereg)
## State StateGroups## 1 california West## 2 nevada West## 3 oregon West## 4 washington West## 5 idaho West## 6 montana West
states.class.map <- left_join(states, statereg, by = c("region" = "State"))head(states.class.map)
## long lat group order region subregion StateGroups## 1 -87.46201 30.38968 1 1 alabama <NA> South## 2 -87.48493 30.37249 1 2 alabama <NA> South## 3 -87.52503 30.37249 1 3 alabama <NA> South## 4 -87.53076 30.33239 1 4 alabama <NA> South## 5 -87.57087 30.32665 1 5 alabama <NA> South## 6 -87.58806 30.32665 1 6 alabama <NA> South
ggplot() + geom_polygon(data=states.class.map, aes(x=long, y=lat, group=group, fill = StateGroups), colour = I("black"))+ coord_map()+theme(legend.position="bottom")
library(devtools)install_github("mccormackandrew/mapcan", build_vignettes = TRUE)library(mapcan)canada_map<-mapcan(boundaries = "province", type="standard",territories=TRUE)head(canada_map)
## long lat order hole piece pr_sgc_code group pr_english## 1 2278204 1261783 1 FALSE 1 10 10.1 Newfoundland and Labrador## 2 2294272 1251745 2 FALSE 1 10 10.1 Newfoundland and Labrador## 3 2300435 1250534 3 FALSE 1 10 10.1 Newfoundland and Labrador## 4 2306656 1243299 4 FALSE 1 10 10.1 Newfoundland and Labrador## 5 2315548 1241630 5 FALSE 1 10 10.1 Newfoundland and Labrador## 6 2313319 1237013 6 FALSE 1 10 10.1 Newfoundland and Labrador## pr_french pr_alpha## 1 Terre-Neuve-et-Labrador NL## 2 Terre-Neuve-et-Labrador NL## 3 Terre-Neuve-et-Labrador NL## 4 Terre-Neuve-et-Labrador NL## 5 Terre-Neuve-et-Labrador NL## 6 Terre-Neuve-et-Labrador NL
#Set theme options:theme_set(theme_grey() + theme(axis.text=element_blank(), axis.ticks=element_blank(), axis.title.x=element_blank(), axis.title.y=element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.border = element_blank(), panel.background = element_blank(), legend.position="none"))ggplot(canada_map, aes(long, lat, group = group)) + geom_polygon(color="black", fill="white")
library(tidyverse)library(magrittr)data("federal_election_results") federal_election_results %>% as.data.frame() %>% dplyr::filter(election_year=="2015")->electdatacanada_ridings<-mapcan(boundaries = "ridings", type="standard",territories=TRUE)head(canada_ridings)canada_ridings %>% left_join(electdata, by="riding_code") %>% ggplot(aes(long, lat, group = group, fill=factor(party)))+ geom_polygon(color="black") +scale_fill_discrete("Party", type="qual") + theme(legend.position="bottom")
Check out the help file for the map_data
function to find out how to make a map of the world.
Can you figure out how to remove Antarctica from the map?
Use the GDP data you scraped as part of our web-scraping class to shade countries based on their GDP.
Individuals are nested in social networks
Provinces are surrounded by other provinces
Country-level outcomes are often a result of negotiations with other countries:
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |