Last active
January 10, 2018 05:40
-
-
Save etachov/e09d874316da16395988ea842d48b9c0 to your computer and use it in GitHub Desktop.
Make a square-looking map of U.S. National Parks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load libraries | |
library(tidyverse) | |
library(rgdal) | |
# get state data | |
states_map <- map_data("state") %>% | |
# use round to create square border | |
mutate_at(.funs = funs(round), .vars = vars(long, lat)) | |
# get park data from https://catalog.data.gov/dataset/national-park-boundariesf0a4c | |
parks <- readOGR(dsn = "/nps_boundary_shp/", layer = "nps_boundary") | |
# quick and dirty way to drop parks outside of the continental us | |
min_lat <- min(states_map$lat) | |
max_lat <- max(states_map$lat) | |
min_long <- min(states_map$long) | |
max_long <- max(states_map$long) | |
# fortify and edit parks data | |
parks_f <- fortify(parks) %>% | |
filter(long <= max_long & long >= min_long) %>% | |
filter(lat <= max_lat & lat >= min_lat) %>% | |
# once again use round to create square borders | |
# this does some weird things, but i like the effect | |
mutate_at(.funs = funs(round), .vars = vars(long, lat)) | |
# make map | |
ggplot() + | |
geom_polygon(data = states_map, aes(x = long, y = lat, group = group), fill = "#343434", alpha = 1, color = "#317873") + | |
geom_polygon(data = parks_f, aes(x = long, y = lat, group = group), fill = "lightgrey", color ="lightgrey", size = .75) + | |
coord_map("polyconic") + | |
theme_void() + | |
theme(plot.background = element_rect(fill = "#317873")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment