パッケージtotalcensus
を使用して郵便番号でデータを取得する方法は次のとおりです。このパッケージはhttps://github.com/GL-Li/totalcensusから見つけることができます。
library(totalcensus)
library(dplyr)
# http://www.city-data.com/zipmaps/Chicago-Illinois.html to find a list of zip
# code for Chicago
zips <- c(60007, 60018, 60068, 60106, 60131, 60176, 60601, 60602, 60603, 60604,
60605, 60606, 60607, 60608, 60609, 60610, 60611, 60612, 60613, 60614,
60615, 60616, 60617, 60618, 60619, 60620, 60621, 60622, 60623, 60624,
60625, 60626, 60628, 60629, 60630, 60631, 60632, 60633, 60634, 60636,
60637, 60638, 60639, 60640, 60641, 60642, 60643, 60644, 60645, 60646,
60647, 60649, 60651, 60652, 60653, 60654, 60655, 60656, 60657, 60659,
60660, 60661, 60706, 60707, 60714, 60804, 60827)
# read for all US zip codes from 2016 ACS 5-year survey
all_zip_acs5 <- read_acs5year(
year = 2016,
states = "US",
table_contents = "below_poverty = B06012_006", # random example
geo_headers = "ZCTA5",
summary_level = "860"
)
# keep only Chicago zip codes
chicago_zip_acs5 <- filter(all_zip_acs5, ZCTA5 %in% zips)
# GEOID lon lat ZCTA5 state population below_poverty GEOCOMP SUMLEV NAME
# 1 86000US60007 -87.99736 42.00865 60007 <NA> 33733 1064 all 860 ZCTA5 60007
# 2 86000US60018 -87.91176 41.97939 60018 <NA> 30519 2123 all 860 ZCTA5 60018
# 3 86000US60068 -87.84343 42.01176 60068 <NA> 37567 1107 all 860 ZCTA5 60068
# 4 86000US60106 -87.94183 41.95970 60106 <NA> 20215 1147 all 860 ZCTA5 60106
# 5 86000US60131 -87.88426 41.93876 60131 <NA> 18072 943 all 860 ZCTA5 60131
)これは非常に役に立ちます。 B)これを正確にたどったところ、次のエラーが表示されます。 'is.geo.set(geography)のエラー:オブジェクト 'chicagoZipGeo'が見つかりませんでした。 – bmc
スペルミスです。貼り付けをカットすると、上記のzipCodesを使用しました。下のzipコード。それを修正し、それは動作するはずです – sconfluentus
私はちょうどそれを修正し、もう一つの小さなエラーはおそらく何も損傷していないスタイルです...しかし、私はそれをテストし、それは動作します! – sconfluentus