a guest May 16th, 2018 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- #States need to be in equal area projection
- #5070 is EPSG code for the USGS Alber's projection
- states <- st_transform(states, crs = 5070)
- #Create centroids of states
- cntr <- st_centroid(states)
- #Bind these coordinates to the centroid feature
- cntr <- cbind(cntr, st_coordinates(cntr))
- #Get centroid for conterminous US
- xy <- states %>% st_union() %>%
- st_centroid() %>% st_coordinates()
- #Define column 'region' and break US up into regions
- cntr$region <- 'NE'
- cntr$region[cntr$X > xy & cntr$Y < xy] <- 'SE'
- cntr$region[cntr$X < xy & cntr$Y < xy] <- 'SW'
- cntr$region[cntr$X < xy & cntr$Y > xy] <- 'NW'
- #Region IDs back to state polygons
- states$region <- cntr$region
- #Dissolve by region ID
- regions <- states %>%
- group_by(region) %>%
- plot(cntr['region'], pch = 19, add=T)
RAW Paste Data