-
Notifications
You must be signed in to change notification settings - Fork 0
/
border-maps.R
62 lines (50 loc) · 2.26 KB
/
border-maps.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
## 'Border' Maps
library(sf)
library(tidyverse)
# Grab some US state shapefiles from the census bureau
#
# dir.create("data")
# Uncomment the next lines to download and unpack the data
# download.file("http://www2.census.gov/geo/tiger/GENZ2016/shp/cb_2016_us_state_20m.zip",
# "data/cb_2016_us_state_20m.zip")
# unzip("data/cb_2016_us_state_20m.zip", exdir = "data")
# Transform to a projection from long-lat form
us <- st_read("./data/cb_2016_us_state_20m.shp") %>%
st_transform("+init=epsg:26978")
# 100 miles in meters
meters <- 160934.4
not_contiguous_us <- c("Puerto Rico", "Alaska", "Hawaii")
us_filt <- filter(us, !(NAME %in% not_contiguous_us))
us_outline <- st_union(us_filt) # contiguous outline
not_border_zone <- st_buffer(us_outline, dist = -meters) # mainland outline 100m in
border_zone <- st_difference(us_outline, not_border_zone)
ggplot() +
geom_sf(data = us_filt, fill = "white", size = 0.2) +
geom_sf(data = border_zone, alpha = 0.4, fill = "darkgrey", color = NA) +
labs(title = "'Border' Zone in the Contiguous United States")
# ggsave("pics/border-zone-contiguous-us.pdf")
# base version
# png("pics/border-zone-contiguous-us.png",
# width = 8, height = 6.5, units = "in", res = 300)
# plot(st_geometry(us_filt), lwd = 2,
# main = "'Border' Zone in Contiguous United States",
# graticule = TRUE, col = "white", col_graticule = "lightgrey")
# plot(border_zone, lty = "blank", col = rgb(0.7, 0.7, 0.7, 0.4), add = TRUE)
# dev.off()
# And here's Alaska by itself, to scale for once.
us_filt <- filter(us, NAME == "Alaska")
us_outline <- st_union(us_filt) # Alaska outline
not_border_zone <- st_buffer(us_outline, dist = -meters) # Alaska outline 100m in
border_zone <- st_difference(us_outline, not_border_zone)
ggplot() +
geom_sf(data = us_filt, fill = "white", size = 0.2) +
geom_sf(data = border_zone, alpha = 0.4, fill = "darkgrey", color = NA) +
labs(title = "'Border' Zone in Alaska")
# ggsave("pics/border-zone-alaska.pdf")
# base version
# png("pics/border-zone-alaska.png",
# width = 8, height = 6.5, units = "in", res = 300)
# plot(st_geometry(us_filt), lwd = 2,
# graticule = TRUE, col = "white", col_graticule = "lightgrey")
# plot(border_zone, lty = "blank", col = rgb(0.7, 0.7, 0.7, 0.4), add = TRUE)
# dev.off()