Movatterモバイル変換


[0]ホーム

URL:


Version:1.0.0
Title:US Maps Including Alaska and Hawaii
Description:Obtain United States map data frames of varying region types (e.g. county, state). The map data frames include Alaska and Hawaii conveniently placed to the bottom left, as they appear in most maps of the US. Convenience functions for plotting choropleths, visualizing spatial data, and working with FIPS codes are also provided.
Depends:R (≥ 3.5.0)
License:GPL (≥ 3)
Encoding:UTF-8
Language:en-US
LazyData:true
URL:https://usmap.dev
BugReports:https://github.com/pdil/usmap/issues
Imports:rlang, usmapdata (≥ 1.0.0)
Suggests:covr, ggplot2 (≥ 3.5.0), ggrepel, knitr, proto, rmarkdown,scales, sf, spelling, testthat (≥ 3.0.0), vdiffr, withr
RoxygenNote:7.3.2
VignetteBuilder:knitr
Config/testthat/edition:3
NeedsCompilation:no
Packaged:2025-08-29 01:23:38 UTC; paolo
Author:Paolo Di Lorenzo [aut, cph, cre]
Maintainer:Paolo Di Lorenzo <paolo@dilorenzo.org>
Repository:CRAN
Date/Publication:2025-08-29 08:50:02 UTC

usmap: US maps including Alaska and Hawaii

Description

It is usually difficult or inconvenient to create US maps thatinclude Alaska, Hawaii, and even Puerto Rico in a convenient spot. All mapdata frames produced by this package use the US National Atlas Equal Areaprojection.

Map data

Alaska, Hawaii, and Puerto Rico have been manually moved to a new location so thattheir new coordinates place them to the bottom-left corner ofthe map. These maps can be accessed by using theus_map() function.

The function provides the ability to retrieve maps with eitherstate borders or county borders using theregions parameterfor convenience.

States (or counties) can be included and excluded using the providedinclude andexclude parameters. These parameters can be usedtogether with any combination of names, abbreviations, or FIPS code tocreate more complex maps.

FIPS lookup tools

Several functions have been included to lookup the US state or countypertaining to a FIPS code.

Likewise a reverse lookup can be done where a FIPS code can be used toretrieve the associated states or counties. This can be useful whenpreparing data to be merged with the map data frame.

Plot US map data

A convenience functionplot_usmap() has been included whichtakes similar parameters tous_map() and returns aggplot2::ggplot2object. Since the output is aggplot object, other layers can beadded such as scales, themes, and labels. Including data in the function callwill color the map according to the values in the data, creating a choropleth.

Transforming data

It is also possible to add spatial data to the map, in the form of eitherdata frames or simple features (sf::sf) objects. If necessary, thedata can be transformed to be in the same coordinate reference system asusmap by usingusmap_transform() and then plotted usingggplot2::geom_sf().

Author(s)

Paolo Di Lorenzo

References

Rudis, Bob. "Moving The Earth (well, Alaska & Hawaii) With R."Blog post. Rud.is., 16 Nov. 2014. Web. 10 Aug. 2015.https://rud.is/b/2014/11/16/moving-the-earth-well-alaska-hawaii-with-r/.

See Also

Helpful links:


East North Central census division

Description

US Census Bureau regional division containing Illinois, Indiana, Michigan,Ohio, and Wisconsin.

Usage

.east_north_central

Format

An object of classcharacter of length 5.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .east_north_central, labels = TRUE)

East South Central census division

Description

US Census Bureau regional division containing Alabama, Kentucky,Mississippi, and Tennessee.

Usage

.east_south_central

Format

An object of classcharacter of length 4.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .east_south_central, labels = TRUE)

Mid-Atlantic census division

Description

US Census Bureau regional division containing New Jersey, New York,and Pennsylvania.

Usage

.mid_atlantic

Format

An object of classcharacter of length 3.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .mid_atlantic, labels = TRUE)

Midwest census region

Description

US Census Bureau region containing the East North Central and WestNorth Central divisions. This region was designated as "North Central Region"prior to June 1984.

Usage

.midwest_region

Format

An object of classcharacter of length 12.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .midwest_region, labels = TRUE)

Mountain census division

Description

US Census Bureau regional division containing Arizona, Colorado, Idaho,Montana, Nevada, New Mexico, Utah, and Wyoming.

Usage

.mountain

Format

An object of classcharacter of length 8.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .mountain, labels = TRUE)

New England census division

Description

US Census Bureau regional division containing Connecticut, Maine,Massachusetts, New Hampshire, Rhode Island, and Vermont.

Usage

.new_england

Format

An object of classcharacter of length 6.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .new_england, labels = TRUE)

North-Central census region

Description

Former US Census Bureau region containing the East North Central and WestNorth Central divisions. This region has been designated as "Midwest"since June 1984.

Usage

.north_central_region

Format

An object of classcharacter of length 12.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .north_central_region, labels = TRUE)

Northeast census region

Description

US Census Bureau region containing the New England and Mid-Atlanticdivisions.

Usage

.northeast_region

Format

An object of classcharacter of length 9.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .northeast_region, labels = TRUE)

Pacific census division

Description

US Census Bureau regional division containing Alaska, California, Hawaii,Oregon, and Washington.

Usage

.pacific

Format

An object of classcharacter of length 5.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .pacific, labels = TRUE)

South Atlantic census division

Description

US Census Bureau regional division containing Delaware, Florida, Georgia,Maryland, North Carolina, South Carolina, Virginia,District of Columbia, and West Virginia.

Usage

.south_atlantic

Format

An object of classcharacter of length 9.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .south_atlantic, labels = TRUE)

South census region

Description

US Census Bureau region containing the South Atlantic, East South Central,and West South Central divisions.

Usage

.south_region

Format

An object of classcharacter of length 17.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .midwest_region, labels = TRUE)

West North Central census division

Description

US Census Bureau regional division containing Iowa, Kansas, Minnesota,Missouri, Nebraska, North Dakota, and South Dakota.

Usage

.west_north_central

Format

An object of classcharacter of length 7.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .west_north_central, labels = TRUE)

West census region

Description

US Census Bureau region containing the Mountain and Pacific divisions.

Usage

.west_region

Format

An object of classcharacter of length 13.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .midwest_region, labels = TRUE)

West South Central census division

Description

US Census Bureau regional division containing Arkansas, Louisiana, Oklahoma,and Texas.

Usage

.west_south_central

Format

An object of classcharacter of length 4.

Details

Seehttps://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

Examples

plot_usmap(include = .west_south_central, labels = TRUE)

Most populous city in each state (2010)

Description

The most populous city in each US state, as of the 2010 US Census.

The data is formatted for transforming withusmap_transform().Once the longitude and latitude is transformed, it can be added toplot_usmap() usingggplot2::ggplot() layers.

Usage

data(citypop)

Format

A data frame with 51 rows and 5 variables.

Details

References


Population estimates (2022), county level

Description

US census population estimates by county for 2022.

The data is formatted for easy merging with output fromus_map().

Usage

data(countypop)

Format

A data frame with 3222 rows and 4 variables.

Details

References


Poverty percentage estimates (2021), county level

Description

US census poverty percentage estimates by county for 2021.

The data is formatted for easy merging with output fromus_map().

Usage

data(countypov)

Format

A data frame with 3194 rows and 4 variables.

Details

References


Earthquakes (2019)

Description

US earthquakes with a magnitude of 2.5 or greater, occurring in thefirst half of 2019, from January 1 to June 30, from USGS.

The data is formatted for transforming withusmap_transform().Once the longitude and latitude is transformed, it can be added toplot_usmap() usingggplot2::ggplot() layers.

Usage

data(earthquakes)

Format

A data frame with 2254 rows and 3 variables.

Details

References


Retrieve FIPS code for either a US state or county

Description

Each US state and county has a unique FIPS(Federal Information Processing Standards) code. Usethis function to obtain the FIPS code for a state orcounty.

Usage

fips(state, county = c(), data_year = NULL)

Arguments

state

The state(s) for which to obtain a FIPS code(s).Can be entered as either a state abbreviation or full name (case-insensitive).

state can be entered as either a single state or a vector of states.Ifstate is a vector,county must be omitted.

county

The county for which to obtain a FIPS code.Can be entered with or without "county" (case-insensitive).

data_year

The year for which to obtain FIPS data. If the value is NULL,the most recent year's data is used. If the provided year is not found fromthe available map data sets, the next most recent year's data is used.The default is NULL, i.e. the most recent available year is used.

Details

State and county FIPS (Federal Information Processing Standards) aretwo and five digit codes, respectively. They uniquely identify all states andcounties within the United States. The first two digits of the five digit countycodes correspond to the state that the county belongs to. FIPS codes also existfor US territories and minor outlying islands, though this package only providesinformation for the 50 US states (and their associated counties andcensus designated areas).

Value

The FIPS code(s) of givenstate orcounty.

If only states are entered, a vector of length equal to the number of statesis returned. If any states are not found or are invalid,NA is returned in their place.

If a state and county are entered, a single value with the FIPS codefor the given county is returned. If the county is invalid for the given state,an error is thrown.

If bothstate andcounty are omitted, the entire list of available FIPScodes is returned, sorted by the state's abbreviation (e.g. Alaska (AK) comesbefore Alabama (AL)).

Note

Astate must be included when searching forcounty,otherwise multiple results may be returned for duplicate county names.

See Also

fips_info()

Examples

fips()fips("NJ")fips("California")fips(c("AK", "CA", "UT"))fips("CA", county = "orange")fips(state = "AL", county = "autauga")fips(state = "Alabama", county = "Autauga County")

Retrieve states or counties using FIPS codes

Description

Retrieve states or counties using FIPS codes

Usage

fips_info(fips, sortAndRemoveDuplicates = FALSE, data_year = NULL)## S3 method for class 'numeric'fips_info(fips, sortAndRemoveDuplicates = FALSE, data_year = NULL)## S3 method for class 'character'fips_info(fips, sortAndRemoveDuplicates = FALSE, data_year = NULL)

Arguments

fips

A one to five digit, eithernumericorcharacter, vector of FIPS codes for which to look up states or counties.States have a two digit FIPS code and counties have a five digit FIPScode (where the first 2 numbers pertain to the state).

sortAndRemoveDuplicates

Whether or not to sort the output and removeduplicates. By default, the output will be returned in the order ofthe values provided to thefips parameter. Set this parameter toTRUEto return the output sorted by FIPS with a single instance of each FIPS.

data_year

The year for which to obtain FIPS data. If the value is NULL,the most recent year's data is used. If the provided year is not found fromthe available map data sets, the next most recent year's data is used.The default is NULL, i.e. the most recent available year is used.

Value

A data frame with the states or counties and the associatedFIPS codes.

Iffips is omitted, the data frame containing all available states isreturned.

See Also

fips()

Examples

fips_info(2)fips_info("2")fips_info(c("02", "03", "04"))fips_info(2016)fips_info(c("02016", "02017"), sortAndRemoveDuplicates = TRUE)

Gets FIPS info for either states or counties depending on input.Helper function for S3 methodfips_info().

Description

Gets FIPS info for either states or counties depending on input.Helper function for S3 methodfips_info().

Usage

get_fips_info(fips, sortAndRemoveDuplicates, data_year = NULL)

Join county or state level data to US map data

Description

Join county or state level data to US map data

Usage

map_with_data(  data,  values = "values",  include = c(),  exclude = c(),  na = NA,  data_year = NULL)

Arguments

data

The data that should be joined to a US map. Thisparameter should be a data frame consisting of two columns,a fips code (2 characters for state, 5 characters for county)and the value that should be associated with that region. Thecolumns ofdatamust befips orstate andthe value of thevalues parameter. If bothfips andstateare provided, this function uses thefips.

values

The name of the column that contains the values to be associatedwith a given region. The default is"values".

include

The regions to include in the resulting map. Ifregions is"states"/"state", the value can be either a state name, abbreviation or FIPS code.For counties, the FIPS must be provided as there can be multiple counties with thesame name. If states are provided in the county map, only counties in the included stateswill be returned.

exclude

The regions to exclude in the resulting map. Ifregions is"states"/"state", the value can be either a state name, abbreviation or FIPS code.For counties, the FIPS must be provided as there can be multiple counties with thesame name. The regions listed in theinclude parameter take precedence overregions listed inexclude. If both parameters include the same region(s) theywill be included in the map.

na

The value to be inserted for states or counties that don't havea value indata. This value must be of the same type as thevaluecolumn ofdata.

data_year

The year for which to obtain map data.If the value isNULL, the most recent year's data is used. If theprovided year is not found from the available map data sets, the next mostrecent year's data is used. This can be used if an older data set is beingplotted on the US map so that the data matches the map more accurately.Therefore, the provided value should match the year of the plotted data set.The default isNULL, i.e. the most recent available year is used.

Value

A data frame composed of the map data frame (fromus_map()) exceptan extra column containing the values indata is included.

The result can be plotted usingggplot2::ggplot() orplot_usmap().

See Also

plot_usmap()

Examples

state_data <- data.frame(fips = c("01", "02", "04"), values = c(1, 5, 8))df <- map_with_data(state_data, na = 0)state_data <- data.frame(state = c("AK", "CA", "Utah"), values = c(6, 9, 3))df <- map_with_data(state_data, na = 0)

Transformsf coordinates tousmap transform

Description

Internal function with common functionality for transforming coordinates.Using this function directly is not recommended.

Usage

perform_transform(data, ...)

Conveniently plot basic US map

Description

Conveniently plot basic US map

Usage

plot_usmap(  regions = c("states", "state", "counties", "county"),  include = c(),  exclude = c(),  data = data.frame(),  values = "values",  theme = theme_map(),  labels = FALSE,  label_color = "black",  data_year = NULL,  ...)

Arguments

regions

The region breakdown for the map, can be one of("states","state","counties","county").The default is"states".

include

The regions to include in the resulting map. Ifregions is"states"/"state", the value can be either a state name, abbreviation or FIPS code.For counties, the FIPS must be provided as there can be multiple counties with thesame name. If states are provided in the county map, only counties in the included stateswill be returned.

exclude

The regions to exclude in the resulting map. Ifregions is"states"/"state", the value can be either a state name, abbreviation or FIPS code.For counties, the FIPS must be provided as there can be multiple counties with thesame name. The regions listed in theinclude parameter take precedence overregions listed inexclude. If both parameters include the same region(s) theywill be included in the map.

data

A data frame containing values to plot on the map. Thisparameter should be a data frame consisting of two columns,a FIPS code (2 characters for state, 5 characters for county)and the value that should be associated with that region. Thecolumns ofdatamust befips orstate andthe value of thevalues parameter.

values

The name of the column that contains the values to be associatedwith a given region. The default is"value".

theme

The theme that should be used for plotting the map. The defaultistheme_map fromggthemes.

labels

Whether or not to display labels on the map. Labels are not displayedby default.

label_color

The color of the labels to display. Corresponds to thecoloroption in theggplot2::aes() mapping. The default is"black".Click herefor more color options.

data_year

The year for which to obtain map data.If the value isNULL, the most recent year's data is used. If theprovided year is not found from the available map data sets, the next mostrecent year's data is used. This can be used if an older data set is beingplotted on the US map so that the data matches the map more accurately.Therefore, the provided value should match the year of the plotted data set.The default isNULL, i.e. the most recent available year is used.

...

Other arguments to pass toggplot2::aes(). These areoften aesthetics, used to set an aesthetic to a fixed value, likecolor = "red"orlinewidth = 3. They affect the appearance of the polygons used to renderthe map (for example fill color, line color, line thickness, etc.). If any ofcolor/colour,fill, orlinewidth are not specified theyare set to their default values ofcolor="black",fill="white",andlinewidth=0.4.

Details

By default, Puerto Rico is not plotted unless it is specifically includedviainclude = c("PR") etc. The default behavior can be changed by settingthe environment variableUSMAP_DEFAULT_EXCLUDE_PR = FALSE.

Value

Aggplot2::ggplot object that contains a basicUS map with the described parameters. Since the result is aggplotobject, it can be extended with moreggplot2::Geom layers, scales, labels,themes, etc.

See Also

usmap,ggplot2::theme()

Examples

plot_usmap()plot_usmap(regions = "states")plot_usmap(regions = "counties")plot_usmap(regions = "state")plot_usmap(regions = "county")# Output is ggplot object so it can be extended# with any number of ggplot layerslibrary(ggplot2)plot_usmap(include = c("CA", "NV", "ID", "OR", "WA")) +  labs(title = "Western States")# Color maps with dataplot_usmap(data = statepop, values = "pop_2022")# Include labels on map (e.g. state abbreviations)plot_usmap(data = statepop, values = "pop_2022", labels = TRUE)# Choose color for labelsplot_usmap(data = statepop, values = "pop_2022", labels = TRUE, label_color = "white")

Population estimates (2022), state level

Description

US census population estimates by state for 2022.

The data is formatted for easy merging with output fromus_map().

Usage

data(statepop)

Format

A data frame with 52 rows and 4 variables.

Details

References


Poverty percentage estimates (2021), state level

Description

US census poverty percentage estimates by state for 2021.

The data is formatted for easy merging with output fromus_map().

Usage

data(statepov)

Format

A data frame with 51 rows and 4 variables.

Details

References


Merge while maintaining original sort order

Description

Internal function used byfips_info().

Usage

static_merge(x, y, ...)

See Also

https://stackoverflow.com/a/61560405/7264964


Convenient theme map

Description

This creates a nice map theme for use inplot_usmap().It originated from theggthemes package located at this repository:https://github.com/jrnold/ggthemes.

This function was manually rewritten here to avoid the need foranother package import.

Usage

theme_map(base_size = 9, base_family = "")

Retrieve US map data

Description

Retrieve US map data

Usage

us_map(  regions = c("states", "state", "counties", "county"),  include = c(),  exclude = c(),  data_year = NULL)

Arguments

regions

The region breakdown for the map, can be one of("states","state","counties","county").The default is"states".

include

The regions to include in the resulting map. Ifregions is"states"/"state", the value can be either a state name, abbreviation or FIPS code.For counties, the FIPS must be provided as there can be multiple counties with thesame name. If states are provided in the county map, only counties in the included stateswill be returned.

exclude

The regions to exclude in the resulting map. Ifregions is"states"/"state", the value can be either a state name, abbreviation or FIPS code.For counties, the FIPS must be provided as there can be multiple counties with thesame name. The regions listed in theinclude parameter take precedence overregions listed inexclude. If both parameters include the same region(s) theywill be included in the map.

data_year

The year for which to obtain map data.If the value isNULL, the most recent year's data is used. If theprovided year is not found from the available map data sets, the next mostrecent year's data is used. This can be used if an older data set is beingplotted on the US map so that the data matches the map more accurately.Therefore, the provided value should match the year of the plotted data set.The default isNULL, i.e. the most recent available year is used.

Value

Ansf data frame of US map coordinates divided by the desiredregions.

See Also

usmapdata::us_map() of which this function is a wrapper for.

Examples

str(us_map())df <- us_map(regions = "counties")west_coast <- us_map(include = c("CA", "OR", "WA"))excl_west_coast <- us_map(exclude = c("CA", "OR", "WA"))ct_counties_as_of_2022 <- us_map(regions = "counties", include = "CT", data_year = 2022)

usmap coordinate reference system

Description

This coordinate reference system (CRS) representsthe canonical projection used by theusmap package. It canbe used to transform shape files, spatial points, spatial dataframes, etc. to the same coordinate representation that is usedby theplot_usmap function.

Usage

usmap_crs()

Convert spatial data to usmap projection

Description

Converting a spatial object of map coordinates willallow those points to line up with the regular usmap plot by applyingthe same US National Atlas Equal Area projection (including Alaska andHawaii of course) to those points as well.

The inputdata is assumed to contain longitude and latitude coordinatesby default. If this is not the case, provide ansf::st_crs objectto thecrs parameter with the appropriate coordinate reference system.

Usage

usmap_transform(data, ...)## S3 method for class 'sf'usmap_transform(data, ...)## S3 method for class 'data.frame'usmap_transform(data, ..., input_names = c("lon", "lat"), output_names = NULL)

Arguments

data

A data frame containing coordinates in a two column formatwhere the first column represents longitude and the second data framerepresents latitude. The names of the data frame column do not matter,just that the order of the columns is kept intact.

...

Additional parameters passed ontosf::st_as_sf.By default,crs = sf::st_crs(4326) is used, implying longitude and latitudecoordinates.

input_names

A character vector of length two which specifies thelongitude and latitude columns of the input data (the ones that should betransformed), respectively. Only required if the input data isadata.frame object. Defaults toc("lon", "lat").

output_names

Defunct, this parameter is no longer used. The outputof this function will have a column named"geometry" with the transformedcoordinates. This parameter may be removed in a future version.

Value

Ansf object containing the transformed coordinates from theinput data frame with the US National Atlas Equal Area projection applied.The transformed columns will be appended to the data frame so that alloriginal columns should remain intact.

Examples

data <- data.frame(  lon = c(-74.01, -95.36, -118.24, -87.65, -134.42, -157.86),  lat = c(40.71, 29.76, 34.05, 41.85, 58.30, 21.31),  pop = c(8398748, 2325502, 3990456, 2705994, 32113, 347397))# Transform datatransformed_data <- usmap_transform(data)# Plot transformed data on maplibrary(ggplot2)plot_usmap() + geom_sf(  data = transformed_data,  aes(size = pop),  color = "red", alpha = 0.5)

US Major Rivers (2010)

Description

Major rivers in the United States.

The data is can be transformed withusmap_transform().Once theShape strings are transformed, it can be added toplot_usmap() using aggplot2::geom_sf() layer.

Usage

data(usrivers)

Format

A simple features (sf) data frame with 55 rows and 5 variables.

Details

References


[8]ページ先頭

©2009-2025 Movatter.jp