{"id":18859669,"url":"https://github.com/pdil/usmap","last_synced_at":"2025-04-07T11:07:51.746Z","repository":{"id":36902617,"uuid":"41209636","full_name":"pdil/usmap","owner":"pdil","description":"🗺 Create US maps including Alaska and Hawaii in R","archived":false,"fork":false,"pushed_at":"2024-12-28T03:49:10.000Z","size":161068,"stargazers_count":75,"open_issues_count":4,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-31T09:09:08.635Z","etag":null,"topics":["counties","data","fips","geodata","mapping","r","states","usa"],"latest_commit_sha":null,"homepage":"https://usmap.dev/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pdil.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"pdil"}},"created_at":"2015-08-22T14:01:45.000Z","updated_at":"2025-02-19T11:41:43.000Z","dependencies_parsed_at":"2024-03-22T00:25:25.192Z","dependency_job_id":"9cd0f37d-fe42-474e-bb00-0e22d67e3e0d","html_url":"https://github.com/pdil/usmap","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdil%2Fusmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdil%2Fusmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdil%2Fusmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdil%2Fusmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pdil","download_url":"https://codeload.github.com/pdil/usmap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247640463,"owners_count":20971557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["counties","data","fips","geodata","mapping","r","states","usa"],"created_at":"2024-11-08T04:18:51.141Z","updated_at":"2025-04-07T11:07:51.729Z","avatar_url":"https://github.com/pdil.png","language":"R","funding_links":["https://github.com/sponsors/pdil"],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include=FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  dpi = 300,\n  comment = \"#\u003e\",\n  fig.align = \"center\",\n  fig.path = \"man/figures/README-\",\n  fig.width = 15,\n  dev.args = list(bg = \"transparent\")\n)\n```\n\n# 🗺 usmap\n\n\u003c!-- badges: start --\u003e\n[![CRAN](https://www.r-pkg.org/badges/version/usmap?color=blue)](https://cran.r-project.org/package=usmap)\n[![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/usmap)](https://cran.r-project.org/package=usmap)\n[![check](https://github.com/pdil/usmap/actions/workflows/check.yaml/badge.svg)](https://github.com/pdil/usmap/actions/workflows/check.yaml)\n[![codecov](https://codecov.io/gh/pdil/usmap/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pdil/usmap)\n\u003c!-- badges: end --\u003e\n\n```{r header, echo=FALSE, fig.height=8}\nlibrary(usmap)\nlibrary(ggplot2)\n\n# City population county map (West Region) ####\ncitypop_t \u003c- usmap_transform(citypop)\ncitypop_t_west \u003c- citypop_t[(citypop_t$abbr %in% .west_region) \u0026 (citypop_t$abbr != \"AK\") \u0026 (citypop_t$abbr != \"HI\"), ]\n\nwest_county_citypop_map \u003c-\n  plot_usmap(\"counties\", include = .west_region, exclude = c(\"AK\", \"HI\"), color = \"blue\", fill = \"lightblue\") +\n  geom_sf(data = citypop_t_west, aes(size = city_pop), color = \"red\", alpha = 0.7) +\n  scale_size_continuous(range = c(2, 15), guide = \"none\") +\n  ggrepel::geom_label_repel(\n    data = citypop_t_west,\n    aes(label = most_populous_city, geometry = geometry),\n    size = 5, alpha = 0.8,\n    label.r = unit(0.5, \"lines\"), label.size = 0.5,\n    segment.color = \"red\", segment.size = 1,\n    stat = \"sf_coordinates\", seed = 1002,\n    max.overlaps = 20\n  )\n\n# Population by state with labels ####\nstate_pop_map_labeled \u003c-\n  plot_usmap(data = statepop, values = \"pop_2022\", labels = TRUE) +\n  scale_fill_continuous(low = \"white\", high = \"red\", guide = \"none\")\n\n# Blank county map (Alaska) ####\nak_county_map \u003c-\n  plot_usmap(\"counties\", include = \"AK\", color = \"red\", fill = \"#fffdcf\")\n\n# Poverty by county (South) ####\nsouth_pov_map \u003c-\n  plot_usmap(\"counties\", data = countypov, values = \"pct_pov_2021\",\n             include = .south_region, color = \"white\", size = 0) +\n  scale_fill_continuous(low = \"darkgreen\", high = \"yellow\", guide = \"none\")\n\n# Poverty percentage by county ####\ncounty_pov_map \u003c-\n  plot_usmap(data = countypov, values = \"pct_pov_2021\", size = 0.2) +\n  scale_fill_continuous(low = \"blue\", high = \"yellow\", guide = \"none\")\n\n# Rivers map ####\nrivers_t \u003c- usmap_transform(usrivers)\n\nrivers_map \u003c- plot_usmap(\"counties\", color = \"gray80\") +\n  geom_sf(data = rivers_t, aes(linewidth = Shape_Length), color = \"blue\") +\n  scale_linewidth_continuous(range = c(0.3, 1.5), guide = \"none\")\n\n# Combine plots ####\ncowplot::plot_grid(\n  west_county_citypop_map,\n  state_pop_map_labeled,\n  ak_county_map,\n  south_pov_map,\n  county_pov_map,\n  rivers_map,\n  nrow = 2\n)\n```\n\n## Purpose\n\nTypically in R it is difficult to create nice US [choropleths](https://en.wikipedia.org/wiki/Choropleth_map) 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 simple features ([`sf`](https://github.com/r-spatial/sf)) object for mapping and visualization. This allows the user to easily add spatial data or features to the US map.\n\n## Shape Files\n\nThe shape files that we use to plot the maps in R are located in the [`usmapdata`](https://github.com/pdil/usmapdata) package. These are generated from the [US Census Bureau cartographic boundary files](https://www.census.gov/geographies/mapping-files/time-series/geo/cartographic-boundary.html). Maps at both the state and county levels are included for convenience.\n\n#### Update History\n\n| Date              | `usmap` version | Shape File Year |                                                  Link                                                  |\n|-------------------|:----------------:|:----------------:|:----------------:|\n| May 10, 2024      |      0.7.1       |      2023        | [🔗](https://www.census.gov/geographies/mapping-files/time-series/geo/cartographic-boundary.2023.html) |\n| January 20, 2024  |      0.7.0       |      2022        | [🔗](https://www.census.gov/geographies/mapping-files/time-series/geo/cartographic-boundary.2022.html) |\n| February 27, 2022 |      0.6.0       |      2020        | [🔗](https://www.census.gov/geographies/mapping-files/time-series/geo/cartographic-boundary.2020.html) |\n| June 3, 2018      |      0.3.0       |      2017        |  [🔗](https://www.census.gov/geographies/mapping-files/time-series/geo/carto-boundary-file.2017.html)  |\n| January 29, 2017  |      0.1.0       |      2015        |  [🔗](https://www.census.gov/geographies/mapping-files/time-series/geo/carto-boundary-file.2015.html)  |\n\n## Installation\n\n📦 To install from CRAN (recommended), run the following code in an R console:\n\n```{r install, eval=FALSE}\ninstall.packages(\"usmap\")\n```\n\n### Developer Build\n\n⚠️ The developer build may be unstable and not function correctly, use with caution.\n\nTo install the package from this repository, run the following code in an R console:\n\n```{r install_dev, eval=FALSE}\ninstall.package(\"devtools\")\ndevtools::install_github(\"pdil/usmap\")\n```\n\nThis method will provide the most recent developer build of `usmap`.\n\nTo begin using `usmap`, import the package using the `library` command:\n\n```{r load}\nlibrary(usmap)\n```\n\n## Documentation\n\nTo read the package vignettes, which explain helpful uses of the package, use `vignette`:\n\n```{r vignettes, eval=FALSE}\nvignette(package = \"usmap\")\nvignette(\"usmap1\", package = \"usmap\") # 1. Introduction\nvignette(\"usmap2\", package = \"usmap\") # 2. Mapping the US\nvignette(\"usmap3\", package = \"usmap\") # 3. Advanced Mapping\n```\n\nFor further help with this package, open an [issue](https://github.com/pdil/usmap/issues) or ask a question on Stack Overflow with the [usmap tag](https://stackoverflow.com/questions/tagged/usmap).\n\n## Features\n\n### Map Plots\n\n- Plot US maps\n\n```{r plots, fig.align='center'}\nstates \u003c- plot_usmap(\"states\")\ncounties \u003c- plot_usmap(\"counties\")\n\ncowplot::plot_grid(states, counties, nrow = 1)\n```\n\n\n- Display only certain states, counties, or regions\n\n```{r more_plots}\nlibrary(ggplot2)\n\nmt \u003c- plot_usmap(\"states\", include = .mountain, labels = TRUE)\n\nfl \u003c- plot_usmap(\"counties\", data = countypov, values = \"pct_pov_2021\", include = \"FL\") +\n  scale_fill_continuous(low = \"green\", high = \"red\", guide = \"none\")\n\nne \u003c- plot_usmap(\"counties\", data = countypop, values = \"pop_2022\", include = .new_england) +\n  scale_fill_continuous(low = \"blue\", high = \"yellow\", guide = \"none\")\n\ncowplot::plot_grid(mt, fl, ne, nrow = 1)\n```\n\n\n- Transform and add spatial data to map\n\n```{r sf_plot}\nlibrary(ggplot2)\n\n# Transform included `usrivers` data set\nrivers_transformed \u003c- usmap_transform(usrivers)\n\nriver_map \u003c- plot_usmap(\"counties\", color = \"gray80\") +\n  geom_sf(data = rivers_transformed, aes(linewidth = Shape_Length), color = \"blue\") +\n  scale_linewidth_continuous(range = c(0.3, 1.5), guide = \"none\")\n\n# Transform included `earthquakes` data set\neq_transformed \u003c- usmap_transform(earthquakes)\n\nearthquake_map \u003c- plot_usmap() +\n  geom_sf(data = eq_transformed, aes(size = mag), color = \"red\", alpha = 0.25) +\n  scale_size_continuous(guide = \"none\")\n\ncowplot::plot_grid(river_map, earthquake_map, nrow = 1)\n```\n\n\n### Map Data\n\n- Obtain map data with certain region breakdown\n```{r state_map}\nus_map(regions = \"states\")\n```\n\n```{r county_map}\nus_map(regions = \"counties\")\n```\n\n\n### FIPS Codes\n\n- Look up FIPS codes for states and counties\n\n```{r fips}\nfips(\"New Jersey\")\n\nfips(c(\"AZ\", \"CA\", \"New Hampshire\"))\n\nfips(\"NJ\", county = \"Mercer\")\n\nfips(\"NJ\", county = c(\"Bergen\", \"Hudson\", \"Mercer\"))\n```\n\n\n- Retrieve states or counties with FIPS codes\n\n```{r fips_info}\nfips_info(c(\"34\", \"35\"))\n\nfips_info(c(\"34021\", \"35021\"))\n```\n\n\n- Add FIPS codes to data frame\n\n```{r fips_merge, message=FALSE}\nlibrary(dplyr)\n\ndata \u003c- data.frame(\n  state = c(\"NJ\", \"NJ\", \"NJ\", \"PA\"),\n  county = c(\"Bergen\", \"Hudson\", \"Mercer\", \"Allegheny\")\n)\n\ndata %\u003e% rowwise %\u003e% mutate(fips = fips(state, county))\n```\n\n\n## Additional Information\n\n### Citation Information\n\nThe images generated by `usmap` are not under any copyright restrictions and may be used and distributed freely in any publication or otherwise. \n\nThe underlying shapefiles used to generate the map data are derived from the [US Census Bureau's TIGER/Line Shapefiles](https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.2023.html#list-tab-790442341) which are not copyrighted but do suggest citation. See [section 1.2 of this document](https://www2.census.gov/geo/pdfs/maps-data/data/tiger/tgrshp2023/TGRSHP2023_TechDoc_Ch1.pdf).\n\nIf you wish to cite `usmap` in a publication (appreciated but never required!), you may do so in the following way:\n```{r citation}\ncitation(\"usmap\")\n```\n\n### Coordinate System\n\n`usmap` uses the [US National Atlas Equal Area](https://epsg.io/9311) coordinate system:\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003ccode\u003esf::st_crs(9311)\u003c/code\u003e\u003c/summary\u003e\n\n  ```{r crs, echo=FALSE}\n  sf::st_crs(9311)\n  ```\n\u003c/details\u003e\n\nThis [coordinate reference system (CRS)](https://www.nceas.ucsb.edu/sites/default/files/2020-04/OverviewCoordinateReferenceSystems.pdf) can also be obtained with `usmap::usmap_crs()`.\n\n## Acknowledgments\n\nThe code used to generate the map files was based on this blog post by [Bob Rudis](https://github.com/hrbrmstr): [Moving The Earth (well, Alaska \u0026 Hawaii) With R](https://rud.is/b/2014/11/16/moving-the-earth-well-alaska-hawaii-with-r/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpdil%2Fusmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpdil%2Fusmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpdil%2Fusmap/lists"}