All Projects β†’ pdil β†’ usmap

pdil / usmap

Licence: GPL-3.0 License
πŸ—Ί Create US maps including Alaska and Hawaii in R

Programming Languages

r
7636 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to usmap

geonamescache
geonamescache - a Python library for quick access to a subset of GeoNames data.
Stars: ✭ 76 (+46.15%)
Mutual labels:  geodata, states, fips, counties
node-google-polyline
Encode / decode Google's polyline format
Stars: ✭ 35 (-32.69%)
Mutual labels:  geodata
dswarm
an open-source data management platform for knowledge workers (https://github.com/dswarm/dswarm-documentation/wiki)
Stars: ✭ 57 (+9.62%)
Mutual labels:  mapping
state-codes
Brazilian states 2-letter codes (ISO 3166-2:BR), official abbreviations throughout the country's history
Stars: ✭ 23 (-55.77%)
Mutual labels:  states
php-states
Library to provides Brazilian States as Value Objects in PHP
Stars: ✭ 22 (-57.69%)
Mutual labels:  states
ipython-notebooks
A collection of Jupyter notebooks exploring different datasets.
Stars: ✭ 43 (-17.31%)
Mutual labels:  mapping
FinMesh
A python package that brings together financial and economic data.
Stars: ✭ 20 (-61.54%)
Mutual labels:  usa
leaflet.TravelNotes
A complete mapping application. With this, you prepare a complete travel, adding itineraries and personnal notes to the map. When you travel is complete, you can save it to a file, export the itineraries to a gpx files, print the itineraries and a roadbook with the notes and itineraries description.
Stars: ✭ 31 (-40.38%)
Mutual labels:  mapping
php-schema.org-mapping
A fluent interface to create mappings using Schema.org for Microdata and JSON-LD.
Stars: ✭ 31 (-40.38%)
Mutual labels:  mapping
map-with-me
🌍 Create collaborative maps with your friends (and enemies)
Stars: ✭ 23 (-55.77%)
Mutual labels:  mapping
pylandtemp
Algorithms for computing global land surface temperature and emissivity from NASA's Landsat satellite images with Python.
Stars: ✭ 110 (+111.54%)
Mutual labels:  geodata
NeoCSV
NeoCSV is an elegant and efficient standalone Smalltalk framework to read and write CSV converting to or from Smalltalk objects.
Stars: ✭ 20 (-61.54%)
Mutual labels:  mapping
geo.data.gouv.fr
Trouvez facilement les donnΓ©es gΓ©ographiques dont vous avez besoin
Stars: ✭ 68 (+30.77%)
Mutual labels:  geodata
TrumpWillTriumph
You are running for president of the United States of America. To become president, you must conquer at least 25 of the 50 states. Each state can be conquered by winning a unique challenge.
Stars: ✭ 13 (-75%)
Mutual labels:  usa
direct lidar odometry
Direct LiDAR Odometry: Fast Localization with Dense Point Clouds
Stars: ✭ 202 (+288.46%)
Mutual labels:  mapping
FlowMaps
No description or website provided.
Stars: ✭ 13 (-75%)
Mutual labels:  mapping
LocationMapViewer
Android App to view Locations in a map with support for gpx, kml and kmz data
Stars: ✭ 31 (-40.38%)
Mutual labels:  geodata
buoy
πŸ†˜ A community-based crisis response system. Because friends don't let friends call the cops. πŸ”₯πŸš“πŸ”₯
Stars: ✭ 68 (+30.77%)
Mutual labels:  mapping
pblat
parallelized blat with multi-threads support
Stars: ✭ 34 (-34.62%)
Mutual labels:  mapping
congresstweets
Datasets of the daily Twitter output of Congress.
Stars: ✭ 76 (+46.15%)
Mutual labels:  usa

πŸ—Ί usmap

CRAN Downloads Build Status codecov

View code used to generate these plots: resources/examples.R

Purpose

Typically in R it is difficult to create nice US choropleths that include Alaska and Hawaii. The functions presented here attempt to elegantly solve this problem by manually moving these states to a new location and providing a fortified data frame for mapping and visualization. This allows the user to easily add data to color the map.

Shape Files

The shape files that we use to plot the maps in R are located in the usmapdata package. These are generated from the US Census Bureau cartographic boundary files. Maps at both the state and county levels are included for convenience.

Update History

Date usmap version Shape File Year Link
February 27, 2022 0.6.0 2020 πŸ”—
June 3, 2018 0.3.0 2017 πŸ”—
January 29, 2017 0.1.0 2015 πŸ”—

Installation

To install from CRAN (recommended), run the following code in an R console:

install.packages("usmap")

To install the package from this repository, run the following code in an R console:

# install.package("devtools")
devtools::install_github("pdil/usmap")

Installing using devtools::install_github will provide the most recent developer build of usmap.

⚠️ The developer build may be unstable and not function correctly, use with caution.

To begin using usmap, import the package using the library command:

library(usmap)

Documentation

To read the package vignettes, which explain helpful uses of the package, use vignette:

vignette(package = "usmap")
vignette("introduction", package = "usmap")
vignette("mapping", package = "usmap")
vignette("advanced-mapping", package = "usmap")

For further help with this package, open an issue or ask a question on Stackoverflow with the usmap tag.

Features

  • Obtain map with certain region breakdown
state_map <- us_map(regions = "states")
str(state_map)
#> 'data.frame':	13696 obs. of  9 variables:
#> $ x    : num  1093752 1093244 1093125 1092939 1092914 ...
#> $ y    : num  -1378545 -1374233 -1360891 -1341458 -1338952 ...
#> $ order: int  1 2 3 4 5 6 7 8 9 10 ...
#> $ hole : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
#> $ piece: int  1 1 1 1 1 1 1 1 1 1 ...
#> $ group: chr  "01.1" "01.1" "01.1" "01.1" ...
#> $ fips : chr  "01" "01" "01" "01" ...
#> $ abbr : chr  "AL" "AL" "AL" "AL" ...
#> $ full : chr  "Alabama" "Alabama" "Alabama" "Alabama" ...

county_map <- us_map(regions = "counties")
str(county_map)
#> 'data.frame':	55097 obs. of  10 variables:
#> $ x     : num  811200 829408 828835 855600 859265 ...
#> $ y     : num  -821207 -819722 -814641 -811770 -846158 ...
#> $ order : int  1 2 3 4 5 6 7 8 9 10 ...
#> $ hole  : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
#> $ piece : int  1 1 1 1 1 1 1 1 1 1 ...
#> $ group : chr  "01001.1" "01001.1" "01001.1" "01001.1" ...
#> $ fips  : chr  "01001" "01001" "01001" "01001" ...
#> $ abbr  : chr  "AL" "AL" "AL" "AL" ...
#> $ full  : chr  "Alabama" "Alabama" "Alabama" "Alabama" ...
#> $ county: chr  "Autauga County" "Autauga County" "Autauga County" "Autauga County" ...

  • Look up FIPS codes for states and counties
fips("New Jersey")
#> "34"

fips(c("AZ", "CA", "New Hampshire"))
#> "04" "06" "33"

fips("NJ", county = "Mercer")
#> "34021"

fips("NJ", county = c("Bergen", "Hudson", "Mercer"))
#> "34003" "34017" "34021"
  • Retrieve states or counties with FIPS codes
fips_info(c("34", "35"))
#>         full abbr fips
#> 1 New Jersey   NJ   34 
#> 2 New Mexico   NM   35

fips_info(c("34021", "35021"))
#>         full abbr         county  fips
#> 1 New Jersey   NJ  Mercer County 34021
#> 2 New Mexico   NM Harding County 35021
  • Add FIPS codes to data frame
data <- data.frame(
  state = c("NJ", "NJ", "NJ", "PA"),
  county = c("Bergen", "Hudson", "Mercer", "Allegheny")
)

library(dplyr)
data %>% rowwise %>% mutate(fips = fips(state, county))

#>   state     county  fips
#> 1    NJ     Bergen 34003
#> 2    NJ     Hudson 34017
#> 3    NJ     Mercer 34021
#> 4    PA  Allegheny 42003
  • Plot US maps
plot_usmap("states")
plot_usmap("counties")
  • Display only certain states, counties, or regions
plot_usmap("states", include = .mountain, labels = TRUE)

plot_usmap("counties", data = countypov, values = "pct_pov_2014", include = "FL") +
    ggplot2::scale_fill_continuous(low = "green", high = "red", guide = FALSE)

plot_usmap("counties", data = countypop, values = "pop_2015", include = .new_england) + 
    ggplot2::scale_fill_continuous(low = "blue", high = "yellow", guide = FALSE)

Additional Information

Projection

usmap uses an Albers equal-area conic projection, with arguments as follows:

usmap::usmap_crs()
#> Coordinate Reference System:
#> Deprecated Proj.4 representation:
#>  +proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +ellps=sphere
#> +units=m +no_defs 
#> WKT2 2019 representation:
#> PROJCRS["unknown",
#>     BASEGEOGCRS["unknown",
#>         DATUM["unknown",
#>             ELLIPSOID["Normal Sphere (r=6370997)",6370997,0,
#>                 LENGTHUNIT["metre",1,
#>                     ID["EPSG",9001]]]],
#>         PRIMEM["Greenwich",0,
#>             ANGLEUNIT["degree",0.0174532925199433],
#>             ID["EPSG",8901]]],
#>     CONVERSION["unknown",
#>         METHOD["Lambert Azimuthal Equal Area (Spherical)",
#>             ID["EPSG",1027]],
#>         PARAMETER["Latitude of natural origin",45,
#>             ANGLEUNIT["degree",0.0174532925199433],
#>             ID["EPSG",8801]],
#>         PARAMETER["Longitude of natural origin",-100,
#>             ANGLEUNIT["degree",0.0174532925199433],
#>             ID["EPSG",8802]],
#>         PARAMETER["False easting",0,
#>             LENGTHUNIT["metre",1],
#>             ID["EPSG",8806]],
#>         PARAMETER["False northing",0,
#>             LENGTHUNIT["metre",1],
#>             ID["EPSG",8807]]],
#>     CS[Cartesian,2],
#>         AXIS["(E)",east,
#>             ORDER[1],
#>             LENGTHUNIT["metre",1,
#>                 ID["EPSG",9001]]],
#>         AXIS["(N)",north,
#>             ORDER[2],
#>             LENGTHUNIT["metre",1,
#>                 ID["EPSG",9001]]]] 

This is the same projection used by the US National Atlas.

To obtain the projection used by usmap, use usmap_crs().

Alternatively, the CRS (coordinate reference system) can be created manually with the following command:

sp::CRS(paste("+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0",
              "+a=6370997 +b=6370997 +units=m +no_defs"))

Acknowledgments

The code used to generate the map files was based on this blog post by Bob Rudis:
Moving The Earth (well, Alaska & Hawaii) With R

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].