You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
3.9 KiB

8 years ago
---
output: rmarkdown::github_document
6 years ago
editor_options:
chunk_output_type: console
8 years ago
---
8 years ago
[![Build Status](https://travis-ci.org/hrbrmstr/albersusa.svg?branch=master)](https://travis-ci.org/hrbrmstr/albersusa)
8 years ago
6 years ago
# albersusa
Tools, Shapefiles & Data to Work with an 'AlbersUSA' Composite Projection
## Description
## What's Inside The Tin
The following functions are implemented:
- `counties_sf`: Retreive a U.S. county composite map, optionally with a projection, as a simplefeature
- `usa_sf`: Retreive a U.S. state composite map, optionally with a projection, as a simplefeature
New ones:
- `points_elided`: Shift points around Alaska and Hawaii to the elided area (by @rdinter)
7 years ago
Some legacy ones:
8 years ago
- `usa_composite`: Retreive a U.S. composite map, optionally with a projection
7 years ago
- `counties_composite`: Retreive a U.S. county composite map, optionally with a projection
Pre-canned projection strings:
8 years ago
- `us_aeqd_proj`: Oblique azimuthal equidistant convenience projection
- `us_eqdc_proj`: Equidistant conic convenience projection
- `us_laea_proj`: Albers equal-area conic convenience projection
- `us_lcc_proj`: Lambert conformal conic convenience projection
- `us_longlat_proj`: Generic long/lat convenience projection
The following data sets are included:
- `system.file("extdata/composite_us_states.geojson.gz", package="albersusa")`
- `system.file("extdata/composite_us_counties.geojson.gz", package="albersusa")`
7 years ago
Also, the simplefeatures coluns and `@data` slot of each `SpatialPolygonsDataFrame` has some handy data you can use (like FIPS codes and state/county population information).
8 years ago
6 years ago
## Installation
```{r eval=FALSE}
devtools::install_github("hrbrmstr/albersusa")
```
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width=120)
```
6 years ago
## Usage
8 years ago
```{r message=FALSE, fig.retina=2}
library(albersusa)
library(sf)
8 years ago
library(sp)
library(rgeos)
library(maptools)
library(ggplot2)
library(ggalt)
library(ggthemes)
library(viridis)
library(scales)
# current verison
packageVersion("albersusa")
```
### Simple features
```{r message=FALSE, fig.retina=2}
par(mar=c(0,0,1,0))
us_sf <- usa_sf("laea")
plot(us_sf["pop_2012"])
cty_sf <- counties_sf("aeqd")
plot(cty_sf["census_area"])
```
### Legacy
```{r message=FALSE, warning=FALSE, fig.retina=2}
8 years ago
us <- usa_composite()
8 years ago
dplyr::glimpse(us@data)
plot(us, lwd=0.25)
8 years ago
us <- usa_composite("laea")
plot(us, lwd=0.25)
8 years ago
us <- usa_composite()
us_map <- fortify(us, region="name")
8 years ago
gg <- ggplot()
gg <- gg + geom_map(data=us_map, map=us_map,
aes(x=long, y=lat, map_id=id),
color="#2b2b2b", size=0.1, fill=NA)
gg <- gg + theme_map()
gg + coord_map()
gg + coord_map("polyconic")
gg + coord_proj()
gg + coord_proj(us_laea_proj)
gg + coord_proj(us_aeqd_proj)
gg + coord_proj(us_eqdc_proj)
gg + coord_proj(us_lcc_proj)
gg +
geom_map(data=us@data, map=us_map,
aes(fill=pop_2014, map_id=name),
color="white", size=0.1) +
coord_proj(us_laea_proj) +
scale_fill_viridis(name="2014 Populaton Estimates", labels=comma) +
theme(legend.position="top",
legend.key.width=unit(3, "lines"))
8 years ago
us <- counties_composite()
dplyr::glimpse(us@data)
plot(us, lwd=0.25)
8 years ago
us <- counties_composite("laea")
plot(us, lwd=0.25)
8 years ago
us <- counties_composite()
us_map <- fortify(us, region="fips")
gg <- ggplot()
gg <- gg + geom_map(data=us_map, map=us_map,
aes(x=long, y=lat, map_id=id),
color="#2b2b2b", size=0.1, fill=NA)
gg <- gg + theme_map()
gg + coord_map()
gg + coord_map("polyconic")
gg + coord_proj()
gg + coord_proj(us_laea_proj)
gg + coord_proj(us_aeqd_proj)
gg + coord_proj(us_eqdc_proj)
gg + coord_proj(us_lcc_proj)
```
6 years ago
### Session Info
```{r}
6 years ago
devtools::session_info()
```
6 years ago
## Code of Conduct
6 years ago
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.