Created
August 28, 2018 18:53
-
-
Save John-Brandon/746d2b4c7de653df62881c46621342a1 to your computer and use it in GitHub Desktop.
Pinwheel Alaska
This file contains hidden or 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
| #!/usr/bin/env Rscript | |
| # | |
| # Pinwheel map of Alaska | |
| # | |
| # Author: John Brandon | |
| library(tidyverse) # For data wrangling and ggplotting | |
| library(sf) # Spatial Features | |
| library(USAboundaries) # One of many sources for U.S. state boundaries | |
| # EPSG:3338 [A standard Coordinate Reference System for Alaska] | |
| crs_alaska <- "+proj=aea +lat_1=55 +lat_2=65 +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 | |
| +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" | |
| ak = us_boundaries(state = c('Alaska')) %>% | |
| select(statefp) %>% | |
| st_transform(crs_alaska) | |
| akg = st_geometry(ak) | |
| cntrd = st_centroid(akg) | |
| rot = function(a) { | |
| # Function for rotating spatial features around their centroid | |
| # (see also vignette for `sf` package) | |
| matrix(c(cos(a), sin(a), -sin(a), cos(a)), 2, 2) | |
| } | |
| # Have some fun pinwheeling AK ------------------------------------------------- | |
| expand_bb = 0.25 | |
| col1 = 'white' | |
| col2 = 'yellow' | |
| col3 = 'blue' | |
| spin_map = function(){ | |
| plot(akg, border = 'black', col = col2, expandBB = rep(expand_bb, 4), bgc = col1) | |
| for (ii in seq(0, 2*pi, by = pi/4)){ | |
| ak_rotated = (akg - cntrd) * rot( ii ) * 1.0 + cntrd | |
| plot(ak_rotated, add = TRUE, border = 'black', col = col2) | |
| } | |
| plot(ak, add = TRUE, border = 'black', col = col3) | |
| } | |
| spin_map() # Et voila' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment