Browse Source

counties

pull/2/head
hrbrmstr 8 years ago
parent
commit
cd4f6f9e9b
  1. 1
      NAMESPACE
  2. 2
      R/albersusa.R
  3. 54
      R/counties.r
  4. 5
      R/proj.r
  5. 34
      README.Rmd
  6. 45
      README.html
  7. 87
      README.md
  8. BIN
      README_files/figure-html/unnamed-chunk-3-11.png
  9. BIN
      README_files/figure-html/unnamed-chunk-3-12.png
  10. BIN
      README_files/figure-html/unnamed-chunk-3-13.png
  11. BIN
      README_files/figure-html/unnamed-chunk-3-14.png
  12. BIN
      README_files/figure-html/unnamed-chunk-3-15.png
  13. BIN
      README_files/figure-html/unnamed-chunk-3-16.png
  14. BIN
      README_files/figure-html/unnamed-chunk-3-17.png
  15. BIN
      README_files/figure-html/unnamed-chunk-3-18.png
  16. BIN
      README_files/figure-html/unnamed-chunk-3-19.png
  17. 3150
      inst/extdata/composite_us_counties.geojson
  18. BIN
      inst/extdata/counties.rda
  19. 39
      man/counties_composite.Rd
  20. 1
      man/us_aeqd_proj.Rd
  21. 1
      man/us_eqdc_proj.Rd
  22. 1
      man/us_laea_proj.Rd
  23. 1
      man/us_lcc_proj.Rd
  24. 1
      man/us_longlat_proj.Rd
  25. 6
      man/usa_composite.Rd

1
NAMESPACE

@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand
export(counties_composite)
export(us_aeqd_proj)
export(us_eqdc_proj)
export(us_laea_proj)

2
R/albersusa.R

@ -1,4 +1,4 @@
#' Retreive a U.S. composite map, optionally with a projection
#' Retreive a U.S. state composite map, optionally with a projection
#'
#' The \code{proj} parameter is intende to simplify usage for those using base
#' plotting. If anything but \code{longlat} is specified the composite map

54
R/counties.r

@ -0,0 +1,54 @@
#' Retreive a U.S. county composite map, optionally with a projection
#'
#' The \code{proj} parameter is intende to simplify usage for those using base
#' plotting. If anything but \code{longlat} is specified the composite map
#' will be pre-projected to those
#'
#' This is what's in the SPDF \code{@data} slot:
#'
#' \preformatted{
#' Observations: 3,143
#' Variables: 8
#' $ fips (chr) "01001", "01009", "01017", "01021", "01033", "010...
#' $ state_fips (chr) "01", "01", "01", "01", "01", "01", "01", "01", "...
#' $ county_fips (chr) "001", "009", "017", "021", "033", "045", "051", ...
#' $ name (chr) "Autauga", "Blount", "Chambers", "Chilton", "Colb...
#' $ lsad (chr) "County", "County", "County", "County", "County",...
#' $ census_area (dbl) 594.436, 644.776, 596.531, 692.854, 592.619, 561....
#' #' $ state (chr) "Alabama", "Alabama", "Alabama", "Alabama", "Alab...
#' $ iso_3166_2 (chr) "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "...
#' }
#'
#' @param proj if anything but \code{longlat} is specified, the shapefile will
#' be pre-projected before being returned
#' @export
#' @examples
#' plot(counties_composite())
#'
#' plot(counties_composite("laea"))
counties_composite <- function(proj=c("longlat", "laea", "lcc", "eqdc", "aeqd")) {
# us <- readOGR(system.file("extdata/counties_composite.geojson", package="albersusa"),
# "OGRGeoJSON",
# stringsAsFactors=FALSE,
# verbose=FALSE)
cty <- readRDS(system.file("extdata/counties.rda", package="albersusa"))
proj <- match.arg(proj, c("longlat", "laea", "lcc", "eqdc", "aeqd"))
if (proj != "longlat") {
proj <- switch(proj,
laea=us_laea_proj,
lcc=us_lcc_proj,
eqdc=us_eqdc_proj,
aeqd=us_aeqd_proj)
cty <- sp::spTransform(cty, sp::CRS(proj))
}
cty
}

5
R/proj.r

@ -11,6 +11,7 @@
#' us <- usa_composite()
#' us <- sp::spTransform(us, CRS(us_laea_proj))
#' us <- usa_composite(proj="laea")
#' counties <- counties_composite("laea")
us_laea_proj <- "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"
@ -25,6 +26,7 @@ us_laea_proj <- "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=63
#' @examples
#' us <- usa_composite() # it's the default
#' us <- sp::spTransform(us, CRS(us_longlat_proj))
#' counties <- counties_composite()
us_longlat_proj <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
@ -41,6 +43,7 @@ us_longlat_proj <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,
#' us <- usa_composite()
#' us <- sp::spTransform(us, CRS(us_lcc_proj))
#' us <- usa_composite(proj="lcc")
#' counties <- counties_composite("lcc")
us_lcc_proj <- "+proj=lcc +lat_1=27.11637320883929 +lat_2=53.050729042644335 +lon_0=-95.44921875"
@ -59,6 +62,7 @@ us_lcc_proj <- "+proj=lcc +lat_1=27.11637320883929 +lat_2=53.050729042644335 +lo
#' us <- usa_composite()
#' us <- sp::spTransform(us, CRS(us_eqdc_proj))
#' us <- usa_composite(proj="eqdc")
#' counties <- counties_composite("eqdc")
#'
us_eqdc_proj <- "+proj=eqdc +lat_1=27.11637320883929 +lat_2=53.050729042644335 +lon_0=-95.44921875"
@ -78,5 +82,6 @@ us_eqdc_proj <- "+proj=eqdc +lat_1=27.11637320883929 +lat_2=53.050729042644335 +
#' us <- usa_composite()
#' us <- sp::spTransform(us, CRS(us_aeqd_proj))
#' us <- usa_composite(proj="aeqd")
#' counties <- counties_composite("aeqd")
us_aeqd_proj <- "+proj=aeqd +lat_0=40.08355112574181 +lon_0=-95.44921875"

34
README.Rmd

@ -16,10 +16,12 @@ The following functions are implemented:
- `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
- `counties_composite`: Retreive a U.S. county composite map, optionally with a projection
The following data sets are included:
- `system.file("extdata/composite_us_states.geojson", package="albersusa")` - composite GeoJSON
- `system.file("extdata/composite_us_counties.geojson", package="albersusa")` - composite GeoJSON
### Installation
@ -87,6 +89,38 @@ gg +
scale_fill_viridis(name="2014 Populaton Estimates", labels=comma) +
theme(legend.position="right")
us <- counties_composite()
dplyr::glimpse(us@data)
plot(us)
us <- counties_composite("laea")
plot(us)
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)
```
### Test Results

45
README.html

File diff suppressed because one or more lines are too long

87
README.md

@ -9,10 +9,12 @@ The following functions are implemented:
- `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
- `counties_composite`: Retreive a U.S. county composite map, optionally with a projection
The following data sets are included:
- `system.file("extdata/composite_us_states.geojson", package="albersusa")` - composite GeoJSON
- `system.file("extdata/composite_us_counties.geojson", package="albersusa")` - composite GeoJSON
### Installation
@ -143,6 +145,89 @@ gg +
<img src="README_files/figure-html/unnamed-chunk-3-10.png" title="" alt="" width="672" />
```r
us <- counties_composite()
dplyr::glimpse(us@data)
```
```
## Observations: 3,143
## Variables: 8
## $ fips (chr) "01001", "01009", "01017", "01021", "01033", "01045", "01051", "01065", "01079", "01083", "0109...
## $ state_fips (chr) "01", "01", "01", "01", "01", "01", "01", "01", "01", "01", "01", "01", "01", "05", "05", "06",...
## $ county_fips (chr) "001", "009", "017", "021", "033", "045", "051", "065", "079", "083", "099", "107", "121", "141...
## $ name (chr) "Autauga", "Blount", "Chambers", "Chilton", "Colbert", "Dale", "Elmore", "Hale", "Lawrence", "L...
## $ lsad (chr) "County", "County", "County", "County", "County", "County", "County", "County", "County", "Coun...
## $ census_area (dbl) 594.436, 644.776, 596.531, 692.854, 592.619, 561.150, 618.485, 643.943, 690.678, 559.936, 1025....
## $ state (chr) "Alabama", "Alabama", "Alabama", "Alabama", "Alabama", "Alabama", "Alabama", "Alabama", "Alabam...
## $ iso_3166_2 (chr) "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AR", "AR", "CA",...
```
```r
plot(us)
```
<img src="README_files/figure-html/unnamed-chunk-3-11.png" title="" alt="" width="672" />
```r
us <- counties_composite("laea")
plot(us)
```
<img src="README_files/figure-html/unnamed-chunk-3-12.png" title="" alt="" width="672" />
```r
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()
```
<img src="README_files/figure-html/unnamed-chunk-3-13.png" title="" alt="" width="672" />
```r
gg + coord_map("polyconic")
```
<img src="README_files/figure-html/unnamed-chunk-3-14.png" title="" alt="" width="672" />
```r
gg + coord_proj()
```
<img src="README_files/figure-html/unnamed-chunk-3-15.png" title="" alt="" width="672" />
```r
gg + coord_proj(us_laea_proj)
```
<img src="README_files/figure-html/unnamed-chunk-3-16.png" title="" alt="" width="672" />
```r
gg + coord_proj(us_aeqd_proj)
```
<img src="README_files/figure-html/unnamed-chunk-3-17.png" title="" alt="" width="672" />
```r
gg + coord_proj(us_eqdc_proj)
```
<img src="README_files/figure-html/unnamed-chunk-3-18.png" title="" alt="" width="672" />
```r
gg + coord_proj(us_lcc_proj)
```
<img src="README_files/figure-html/unnamed-chunk-3-19.png" title="" alt="" width="672" />
### Test Results
@ -154,7 +239,7 @@ date()
```
```
## [1] "Mon Mar 28 22:38:24 2016"
## [1] "Mon Mar 28 23:32:07 2016"
```
```r

BIN
README_files/figure-html/unnamed-chunk-3-11.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

BIN
README_files/figure-html/unnamed-chunk-3-12.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 KiB

BIN
README_files/figure-html/unnamed-chunk-3-13.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 KiB

BIN
README_files/figure-html/unnamed-chunk-3-14.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 KiB

BIN
README_files/figure-html/unnamed-chunk-3-15.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 KiB

BIN
README_files/figure-html/unnamed-chunk-3-16.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 KiB

BIN
README_files/figure-html/unnamed-chunk-3-17.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 KiB

BIN
README_files/figure-html/unnamed-chunk-3-18.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 KiB

BIN
README_files/figure-html/unnamed-chunk-3-19.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB

3150
inst/extdata/composite_us_counties.geojson

File diff suppressed because one or more lines are too long

BIN
inst/extdata/counties.rda

Binary file not shown.

39
man/counties_composite.Rd

@ -0,0 +1,39 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/counties.r
\name{counties_composite}
\alias{counties_composite}
\title{Retreive a U.S. county composite map, optionally with a projection}
\usage{
counties_composite(proj = c("longlat", "laea", "lcc", "eqdc", "aeqd"))
}
\arguments{
\item{proj}{if anything but \code{longlat} is specified, the shapefile will
be pre-projected before being returned}
}
\description{
The \code{proj} parameter is intende to simplify usage for those using base
plotting. If anything but \code{longlat} is specified the composite map
will be pre-projected to those
}
\details{
This is what's in the SPDF \code{@data} slot:
\preformatted{
Observations: 3,143
Variables: 8
$ fips (chr) "01001", "01009", "01017", "01021", "01033", "010...
$ state_fips (chr) "01", "01", "01", "01", "01", "01", "01", "01", "...
$ county_fips (chr) "001", "009", "017", "021", "033", "045", "051", ...
$ name (chr) "Autauga", "Blount", "Chambers", "Chilton", "Colb...
$ lsad (chr) "County", "County", "County", "County", "County",...
$ census_area (dbl) 594.436, 644.776, 596.531, 692.854, 592.619, 561....
#' $ state (chr) "Alabama", "Alabama", "Alabama", "Alabama", "Alab...
$ iso_3166_2 (chr) "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "...
}
}
\examples{
plot(counties_composite())
plot(counties_composite("laea"))
}

1
man/us_aeqd_proj.Rd

@ -21,6 +21,7 @@ parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_aeqd_proj)}.
us <- usa_composite()
us <- sp::spTransform(us, CRS(us_aeqd_proj))
us <- usa_composite(proj="aeqd")
counties <- counties_composite("aeqd")
}
\seealso{
Other convenience.projections: \code{\link{us_eqdc_proj}},

1
man/us_eqdc_proj.Rd

@ -21,6 +21,7 @@ parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_eqdc_proj)}.
us <- usa_composite()
us <- sp::spTransform(us, CRS(us_eqdc_proj))
us <- usa_composite(proj="eqdc")
counties <- counties_composite("eqdc")
}
\seealso{

1
man/us_laea_proj.Rd

@ -19,6 +19,7 @@ parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_laea_proj)}.
us <- usa_composite()
us <- sp::spTransform(us, CRS(us_laea_proj))
us <- usa_composite(proj="laea")
counties <- counties_composite("laea")
}
\seealso{
Other convenience.projections: \code{\link{us_aeqd_proj}},

1
man/us_lcc_proj.Rd

@ -19,6 +19,7 @@ parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_lcc_proj)}.
us <- usa_composite()
us <- sp::spTransform(us, CRS(us_lcc_proj))
us <- usa_composite(proj="lcc")
counties <- counties_composite("lcc")
}
\seealso{
Other convenience.projections: \code{\link{us_aeqd_proj}},

1
man/us_longlat_proj.Rd

@ -18,6 +18,7 @@ parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_longlat_proj)}
\examples{
us <- usa_composite() # it's the default
us <- sp::spTransform(us, CRS(us_longlat_proj))
counties <- counties_composite()
}
\keyword{datasets}

6
man/usa_composite.Rd

@ -2,7 +2,7 @@
% Please edit documentation in R/albersusa.R
\name{usa_composite}
\alias{usa_composite}
\title{Retreive a U.S. composite map, optionally with a projection}
\title{Retreive a U.S. state composite map, optionally with a projection}
\usage{
usa_composite(proj = c("longlat", "laea", "lcc", "eqdc", "aeqd"))
}
@ -16,7 +16,7 @@ plotting. If anything but \code{longlat} is specified the composite map
will be pre-projected to those
}
\details{
This is what's in the SPDF \code{@data} portion:
This is what's in the SPDF \code{@data} slot:
\preformatted{
Observations: 51
@ -24,8 +24,6 @@ Variables: 13
$ geo_id (chr) "0400000US04", "0400000US05", "0400000US06", "0400...
$ fips_state (chr) "04", "05", "06", "08", "09", "11", "13", "17", "1...
$ name (chr) "Arizona", "Arkansas", "California", "Colorado", "...
$ lsad (chr) "", "", "", "", "", "", "", "", "", "", "", "", ""...
$ census_area (dbl) 113594.084, 52035.477, 155779.220, 103641.888, 484...
$ iso_3166_2 (chr) "AZ", "AR", "CA", "CO", "CT", "DC", "GA", "IL", "I...
$ census (int) 6392017, 2915918, 37253956, 5029196, 3574097, 6017...
$ pop_estimataes_base (int) 6392310, 2915958, 37254503, 5029324, 3574096, 6017...

Loading…
Cancel
Save