问题
I'm trying to replicate the maps shown in this short example (Choroplethr v3.6.0 is now on CRAN) for California, but I'm having trouble with the tract_choropleth function for areas that are not in NY. I get the error message below. I'm able to import the underlying tract data for all areas, but I'm having trouble mapping the non-NY ones. Thanks in advance.
# Load all packages (DONE)
# Install api key (DONE)
# Get Tract-Level Demographics
ca_stats = get_tract_demographics("california")
# Create choropleth map with the function tract_choropleth
ca_stats$value = ca_stats$per_capita_income
tract_choropleth(ca_stats, "california", title = "2013 Per Capita Income\nCensus Tracts", legend="Dollars")
Error message returned:
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, : Cannot open layer In addition: Warning message: In unzip(file_loc, exdir = cache_dir, overwrite = TRUE) :
error 1 in extracting from zip file
回答1:
I'm the author of the tigris package that choroplethr uses to get Census tract boundaries. That error shows up in the event of a corrupted download from the Census Bureau website. Ari's solution will work; you can also try:
library(tigris)
options(tigris_refresh = TRUE)
This will direct tigris to re-download the shapefile from the Census Bureau website, and allow you to still use caching. Once it is fixed, set options(tigris_refresh = FALSE)
to control future re-downloads.
回答2:
Thank you for using choroplethr.
I have never gotten this error myself, but it's possible that it relates to a caching issue with the tigris package. I say that because it looks very similar to this issue.
Here is the code which solved that user's problem:
library(tigris)
options(tigris_use_cache = FALSE)
That code causes tigris to not use its cache.
Please type that code into your R session and try the choroplethr code again.
来源:https://stackoverflow.com/questions/43481085/tract-choropleth-in-choroplethr-v3-6-0-for-r