Skip to content

Commit

Permalink
Replace us_map implementation with usmapdata call and remove map gene…
Browse files Browse the repository at this point in the history
…ration scripts
  • Loading branch information
pdil committed Feb 9, 2022
1 parent dbe69f4 commit b4bffa4
Show file tree
Hide file tree
Showing 40 changed files with 7 additions and 225,392 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LazyData: true
URL: https://usmap.dev
BugReports: https://github.com/pdil/usmap/issues
Imports:
usmapdata,
utils
Suggests:
covr,
Expand Down
13 changes: 4 additions & 9 deletions R/plot-map.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,11 @@ plot_usmap <- function(regions = c("states", "state", "counties", "county"),

# create label layer
if (labels) {
centroidLabelsColClasses <- c("numeric", "numeric", "character", "character", "character")
if (regions_ == "state") { regions__ <- "states" }
else if (regions_ == "county") { regions__ <- "counties" }
else { regions__ <- regions_ }

if (regions_ == "county" | regions_ == "counties") {
# add extra column for the county name
centroidLabelsColClasses <- c(centroidLabelsColClasses, "character")
}

centroid_labels <- utils::read.csv(system.file("extdata", paste0("us_", regions_, "_centroids.csv"), package = "usmap"),
colClasses = centroidLabelsColClasses,
stringsAsFactors = FALSE)
centroid_labels <- usmapdata::centroid_labels(regions__)

if (length(include) > 0) {
centroid_labels <- centroid_labels[
Expand Down
2 changes: 1 addition & 1 deletion R/transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,5 @@ usmap_crs <- function() {
}

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"))
"+a=6370997 +b=6370997 +units=m +no_defs +datum=WGS84"))
}
39 changes: 1 addition & 38 deletions R/usmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,42 +98,5 @@ if (getRversion() >= "2.15.1")
us_map <- function(regions = c("states", "state", "counties", "county"),
include = c(),
exclude = c()) {

regions_ <- match.arg(regions)

if (regions_ == "state") regions_ <- "states"
else if (regions_ == "county") regions_ <- "counties"

df <- utils::read.csv(system.file("extdata", paste0("us_", regions_, ".csv"), package = "usmap"),
colClasses = col_classes(regions_),
stringsAsFactors = FALSE)

if (length(include) > 0) {
df <- df[df$full %in% include |
df$abbr %in% include |
df$fips %in% include |
substr(df$fips, 1, 2) %in% include, ]
}

if (length(exclude) > 0) {
df <- df[!(df$full %in% exclude |
df$abbr %in% exclude |
df$fips %in% exclude |
substr(df$fips, 1, 2) %in% exclude), ]
}

df
}

#' Map data column classes
#'
#' @keywords internal
col_classes <- function(regions) {
result <- c("numeric", "numeric", "integer", "logical", "integer", rep("character", 4))

if (regions %in% c("county", "counties")) {
result <- c(result, "character") # add extra column for county name
}

result
usmapdata::us_map(regions = regions, include = include, exclude = exclude)
}

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

543 changes: 0 additions & 543 deletions data-raw/maps/cb_2017_us_county_20m/cb_2017_us_county_20m.shp.iso.xml

This file was deleted.

410 changes: 0 additions & 410 deletions data-raw/maps/cb_2017_us_county_20m/cb_2017_us_county_20m.shp.xml

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
310 changes: 0 additions & 310 deletions data-raw/maps/cb_2017_us_state_20m/cb_2017_us_state_20m.shp.ea.iso.xml

This file was deleted.

505 changes: 0 additions & 505 deletions data-raw/maps/cb_2017_us_state_20m/cb_2017_us_state_20m.shp.iso.xml

This file was deleted.

329 changes: 0 additions & 329 deletions data-raw/maps/cb_2017_us_state_20m/cb_2017_us_state_20m.shp.xml

This file was deleted.

Binary file not shown.
99 changes: 0 additions & 99 deletions data-raw/maps/compute-centroids.R

This file was deleted.

Loading

0 comments on commit b4bffa4

Please sign in to comment.