From 418dc324cf4215a93659dacf7f687e37cc8f9f42 Mon Sep 17 00:00:00 2001
From: Kyle Walker Basic usage of tidycensus
access to the 2000, 2010, and 2020 decennial US Census APIs, and
get_acs()
, which grants access to the 1-year and 5-year
American Community Survey APIs.
In this basic example, let’s look at median age by state in 2010:
+In this basic example, let’s look at median age by state in 2020, +with data drawn from the Demographic and Housing Characteristics summary +file:
-age10 <- get_decennial(geography = "state",
- variables = "P013001",
- year = 2010)
+age20 <- get_decennial(geography = "state",
+ variables = "P13_001N",
+ year = 2020,
+ sumfile = "dhc")
-head(age10)
## # A tibble: 6 × 4
-## GEOID NAME variable value
-## <chr> <chr> <chr> <dbl>
-## 1 01 Alabama P013001 37.9
-## 2 02 Alaska P013001 33.8
-## 3 04 Arizona P013001 35.9
-## 4 05 Arkansas P013001 37.4
-## 5 06 California P013001 35.2
-## 6 22 Louisiana P013001 35.8
+## GEOID NAME variable value
+## <chr> <chr> <chr> <dbl>
+## 1 09 Connecticut P13_001N 41.1
+## 2 10 Delaware P13_001N 41.1
+## 3 11 District of Columbia P13_001N 33.9
+## 4 12 Florida P13_001N 43
+## 5 13 Georgia P13_001N 37.5
+## 6 15 Hawaii P13_001N 40.8
The function returns a tibble with four columns by default:
GEOID
, which is an identifier for the geographical unit
associated with the row; NAME
, which is a descriptive name
@@ -155,7 +158,7 @@
As the function has returned a tidy object, we can visualize it quickly with ggplot2:
@@ -431,18 +434,20 @@"sf1"
or "sf2"
(2000 and 2010) and
-"sf3"
or "sf4"
(2000 only) for the various
-summary files. Special island area summary files are available with
-"as"
, "mp"
, "gu"
, or
-"vi"
. For the ACS, use either "acs1"
or
-"acs5"
for the ACS detailed tables, and append
-/profile
for the Data Profile and /subject
for
-the Subject Tables. To browse these variables, assign the result of this
-function to a variable and use the View
function in
-RStudio. An optional argument cache = TRUE
will cache the
-dataset on your computer for future use.
+redistricting files; "dhc"
for the Demographic and Housing
+Characteristics file and "dp"
for the Demographic Profile
+(2020 only), and "sf1"
or "sf2"
(2000 and
+2010) and "sf3"
or "sf4"
(2000 only) for the
+various summary files. Special island area summary files are available
+with "as"
, "mp"
, "gu"
, or
+"vi"
.
+For the ACS, use either "acs1"
or "acs5"
+for the ACS detailed tables, and append /profile
for the
+Data Profile and /subject
for the Subject Tables. To browse
+these variables, assign the result of this function to a variable and
+use the View
function in RStudio. An optional argument
+cache = TRUE
will cache the dataset on your computer for
+future use.
v17 <- load_variables(2017, "acs5", cache = TRUE) @@ -472,32 +477,32 @@
. In turn, when requesting ACS data with tidycensus, it is not necessary to specify theWorking with ACS dataget_acs()
"E"
or"M"
suffix for a variable name. Let’s -fetch median household income data from the 2014-2018 ACS for counties +fetch median household income data from the 2017-2021 ACS for counties in Vermont.vt <- get_acs(geography = "county", variables = c(medincome = "B19013_001"), state = "VT", - year = 2018) + year = 2021) vt
+## 1 50001 Addison County, Vermont medincome 77978 3393 +## 2 50003 Bennington County, Vermont medincome 63448 3413 +## 3 50005 Caledonia County, Vermont medincome 55159 3974 +## 4 50007 Chittenden County, Vermont medincome 81957 2521 +## 5 50009 Essex County, Vermont medincome 48194 3577 +## 6 50011 Franklin County, Vermont medincome 68476 3297 +## 7 50013 Grand Isle County, Vermont medincome 85154 7894 +## 8 50015 Lamoille County, Vermont medincome 66016 4777 +## 9 50017 Orange County, Vermont medincome 67906 2710 +## 10 50019 Orleans County, Vermont medincome 58037 3153 +## 11 50021 Rutland County, Vermont medincome 59751 2133 +## 12 50023 Washington County, Vermont medincome 70128 3014 +## 13 50025 Windham County, Vermont medincome 59195 2060 +## 14 50027 Windsor County, Vermont medincome 63787 2209## # A tibble: 14 × 5 ## GEOID NAME variable estimate moe ## <chr> <chr> <chr> <dbl> <dbl> -## 1 50001 Addison County, Vermont medincome 65093 2424 -## 2 50003 Bennington County, Vermont medincome 53040 2307 -## 3 50005 Caledonia County, Vermont medincome 49348 1842 -## 4 50007 Chittenden County, Vermont medincome 69896 2132 -## 5 50009 Essex County, Vermont medincome 41045 2661 -## 6 50011 Franklin County, Vermont medincome 64258 1568 -## 7 50013 Grand Isle County, Vermont medincome 69583 5812 -## 8 50015 Lamoille County, Vermont medincome 60365 3915 -## 9 50017 Orange County, Vermont medincome 60159 2361 -## 10 50019 Orleans County, Vermont medincome 47915 2193 -## 11 50021 Rutland County, Vermont medincome 54973 1754 -## 12 50023 Washington County, Vermont medincome 62108 2065 -## 13 50025 Windham County, Vermont medincome 52659 1706 -## 14 50027 Windsor County, Vermont medincome 58303 1576
The output is similar to a call to get_decennial()
, but
instead of a value
column, get_acs
returns
estimate
and moe
columns for the ACS estimate
@@ -514,7 +519,7 @@
^Nhmf8`37n3xupbh7pZXe!W9|2kw`69mb%3(`4=;x!*f&18e;K$wbskf|hm
zim%Mf3^-N4vK^K#&NGuue!Tr~T!peEktf!y*+0%q%&4t8H{XmUd3$?D4&
zFJs!F;Law#Bh`kwYu9m s&HAg(rM@u1Q6rh!=FVbAzG8p1^#&yh1jq<&Yy8La}XHY%8s^ZCYbo-qRG@4@nA8F)Pqv3f_Mc<
zA{Zc|U|kPBmOc1kyR@`4VOwOTpt<>iRae<5cd?=S$4{J~ExdgSqB|E7KesU8*US7}
z(9Oxj>c@pWfj|it2Zy=!5oejfkr8E387k+$sHoP}=N6e>#?4@}&_iIvXBj #l|
zSy2qUEp++gpDYhnn18@t0u}COS{#vv8G&A1MTR3Jm=wNGH<+RZ20GJaO3|+zn|b2l
z5gh0^8L8-ikG=VjeUx!v=VvdqvL4lmww1I!^O72w@4(Cxs8ttQ7$GTITF })9ws+5c8+M%|{_X`0~jHv*3xk)w!74
z!+0MW&&c|UF6Vw!(`w;0xm{l8K6lEiny@VqgDqD_viOo$9
zi#SXsOHB0&K%W&6eb(b!aJdYS4R_q|XQ_cQY9*9yP|@aIbBgyj7^j+2`+=^6g@xtZ
zmYa+3+_@9=ukhatR9G%gEUi{nU@wUf*=h+RW8uX_4pGs1;+a6^`e?m-2+PEOAspr5
z?k=BF_wrZV2p!n;{*nd8`QQCM;$vO2d0#+_v6zzrOwTAHS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