| 1 |
set verbose off |
| 2 |
include geoplot.gfn |
| 3 |
|
| 4 |
open us-states.geojson --quiet --frompkg=geoplot |
| 5 |
bundle b = bread($mapfile) |
| 6 |
|
| 7 |
# Shrink Alaska and place underneath the "lower 48" |
| 8 |
matrix shift = {34, -35} |
| 9 |
matrix center = {-150.885, 62.5503} |
| 10 |
matrix scale = {0.3, 0.35} |
| 11 |
geoplot_translate_feature(&b, 48, shift, center, scale) |
| 12 |
|
| 13 |
# Shift Hawaii alongside Alaska |
| 14 |
shift = {51, 5} |
| 15 |
geoplot_translate_feature(&b, 5, shift) |
| 16 |
|
| 17 |
# Switch to revised map |
| 18 |
bwrite(b, "us-rearranged.geojson") |
| 19 |
open us-rearranged.geojson -q |
| 20 |
|
| 21 |
# Add per-state Democratic-win dummy |
| 22 |
strings dem_states = defarray("WA", "OR", "CA", "NV", "AZ", "NM", |
| 23 |
"CO", "MN", "WI", "IL", "MI", "GA", "VA", "PA", "NY", "VT", "NH", |
| 24 |
"ME", "MA", "RI", "CT", "NJ", "DE", "MD", "DC", "HI") |
| 25 |
series D = 0 |
| 26 |
loop i=1..$nobs |
| 27 |
D[i] = nelem(instrings(dem_states, postal[i])) |
| 28 |
endloop |
| 29 |
|
| 30 |
# Display electoral map |
| 31 |
bundle opts = _(title = "USA, 2020", projection = "EPSG2163") |
| 32 |
opts.literal = "set key bottom right" |
| 33 |
strings mycolors = defarray("#D22532", "#244999") |
| 34 |
strings zlabels = defarray("Republican", "Democratic") |
| 35 |
opts.palette = "mycolors,zlabels" |
| 36 |
geoplot(D, opts) |