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.

3.9 KiB

---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
[![Build Status](https://travis-ci.org/hrbrmstr/albersusa.svg?branch=master)](https://travis-ci.org/hrbrmstr/albersusa)

# 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)

Some legacy ones:

- `usa_composite`: Retreive a U.S. composite map, optionally with a projection
- `counties_composite`: Retreive a U.S. county composite map, optionally with a projection

Pre-canned projection strings:

- `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")`

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).

## Installation

```{r eval=FALSE}
devtools::install_github("hrbrmstr/albersusa")
```

```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width=120)
```

## Usage

```{r message=FALSE, fig.retina=2}
library(albersusa)
library(sf)
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}
us <- usa_composite()

dplyr::glimpse(us@data)

plot(us, lwd=0.25)

us <- usa_composite("laea")
plot(us, lwd=0.25)

us <- usa_composite()
us_map <- fortify(us, region="name")

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"))


us <- counties_composite()

dplyr::glimpse(us@data)

plot(us, lwd=0.25)

us <- counties_composite("laea")
plot(us, lwd=0.25)

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)
```

### Session Info

```{r}
devtools::session_info()
```

## Code of Conduct

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.