Learn R Programming

mapping (version 1.2)

loadCoordUS: Get USA coordinates

Description

Loads and returns names, ids, and coordinates for USA, to use with mapping functions and other "map" functions that accept an sf object.

Usage

loadCoordUS(unit = c("country", "region", "division", "state",
                     "county", "district", "district_county", "urban_area"),
            year = c("2018"), scale = c("20", "50", "500"),
            unit_subset = NULL, matchWith = NULL, dir = NULL,
            use_cache = TRUE, use_internet = TRUE, crs = NULL)

Arguments

unit

type of USA unit to link

year

year of the analysis

scale

the scale of the map

unit_subset

character vector of unit names to extract

matchWith

the type of id

dir

local directory in which shape files are stored

use_cache

a logical value indicating whether to use the cache

use_internet

a logical value indicating wheter the coordinates are downloaded from https://github.com/dataallaround/geospatial. If FALSE the maps downloaded during package installation will be used

crs

coordinate reference system. Look at st_crs

Value

A data.frame object with columns indicating names, ids, and the geometry to map.

Details

Coordinates are downloaded from the Github repo https://github.com/dataallaround/geospatial from US folder https://github.com/dataallaround/geospatial/tree/master/US.

If unit is not specified, borders of the USA countries are loaded.

References

https://github.com/dataallaround/geospatial

See Also

loadCoordIT, loadCoordWR

Examples

Run this code
# NOT RUN {
US_coords = loadCoordUS(unit = "state")
str(US_coords)

library(tmap)
tm_shape(US_coords) + tm_borders()

library(mapview)
mapview(US_coords)

## US

US_coords = loadCoordUS()
str(US_coords,1)

library(tmap)
tm_shape(US_coords) + tm_borders()

library(mapview)
mapview(US_coords)

# }
# NOT RUN {
coords_us<- loadCoordUS(unit = "state", unit_subset = c("Florida", "California"))
# }

Run the code above in your browser using DataLab