diff --git a/README.md b/README.md index 658362d..4126f30 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ module-2-data-cleaning - -### Question 3 - -Next, we’ll clean our data by renaming variables: - -``` r -snapCounties %>% - rename( - total_pop = B19058_001E, - total_pop_moe = B19058_001M, - snap = B19058_002E, - snap_moe = B19058_002M - ) -> snapCounties -``` - -## Part 2 - -### Question 4 - -Next, we’ll download the relevant ACS data for Medicaid using -`get_acs()`: - -``` r -medicaidCounties <- get_acs(geography = "county", year = 2019, state = 29, - variables = c("C27007_002", "C27007_012"), - output = "wide", geometry = FALSE) -``` - - ## Getting data from the 2015-2019 5-year ACS - -Now we have the number of male and female Medicaid recipients. - -### Question 5 - -Next, we’ll tidy up the demographic data, including by renaming -variables and summing our male and female Medicaid estimates: - -``` r -medicaidCounties %>% - rename( - medicaid_male = C27007_002E, - medicaid_male_moe = C27007_002M, - medicaid_female = C27007_012E, - medicaid_female_moe = C27007_012M - ) %>% - mutate(medicaid = medicaid_male + medicaid_female) %>% - select(-NAME) -> medicaidCounties -``` - -Now our data are ready to join with our SNAP recipiency data! - -## Part 3 - -### Question 6 - -Finally, we’ll combine our data: - -``` r -services <- left_join(snapCounties, medicaidCounties, by = "GEOID") -``` - -To make sure things went correctly, we’ll preview our data again: - -``` r -mapview(services, zcol = "medicaid") -``` - -![](lab-05_files/figure-gfm/preview-counties-1.png) - -Our data map correctly! diff --git a/assignments/lab-05-replication/docs/lab-05_files/figure-gfm/preview-counties-1.png b/assignments/lab-05-replication/docs/lab-05_files/figure-gfm/preview-counties-1.png deleted file mode 100644 index 04ffd1c..0000000 Binary files a/assignments/lab-05-replication/docs/lab-05_files/figure-gfm/preview-counties-1.png and /dev/null differ diff --git a/assignments/lab-05-replication/docs/lab-05_files/figure-gfm/preview-snap-counties-1.png b/assignments/lab-05-replication/docs/lab-05_files/figure-gfm/preview-snap-counties-1.png deleted file mode 100644 index 97640e0..0000000 Binary files a/assignments/lab-05-replication/docs/lab-05_files/figure-gfm/preview-snap-counties-1.png and /dev/null differ diff --git a/assignments/lab-05-replication/.gitignore b/assignments/lab-2-2-replication/.gitignore similarity index 100% rename from assignments/lab-05-replication/.gitignore rename to assignments/lab-2-2-replication/.gitignore diff --git a/assignments/lab-05-replication/README.md b/assignments/lab-2-2-replication/README.md similarity index 100% rename from assignments/lab-05-replication/README.md rename to assignments/lab-2-2-replication/README.md diff --git a/assignments/lab-05-replication/data/MO_SNAP_Households/MO_SNAP_Households.dbf b/assignments/lab-2-2-replication/data/MO_SNAP_Households/MO_SNAP_Households.dbf similarity index 100% rename from assignments/lab-05-replication/data/MO_SNAP_Households/MO_SNAP_Households.dbf rename to assignments/lab-2-2-replication/data/MO_SNAP_Households/MO_SNAP_Households.dbf diff --git a/assignments/lab-05-replication/data/MO_SNAP_Households/MO_SNAP_Households.prj b/assignments/lab-2-2-replication/data/MO_SNAP_Households/MO_SNAP_Households.prj similarity index 100% rename from assignments/lab-05-replication/data/MO_SNAP_Households/MO_SNAP_Households.prj rename to assignments/lab-2-2-replication/data/MO_SNAP_Households/MO_SNAP_Households.prj diff --git a/assignments/lab-05-replication/data/MO_SNAP_Households/MO_SNAP_Households.shp b/assignments/lab-2-2-replication/data/MO_SNAP_Households/MO_SNAP_Households.shp similarity index 100% rename from assignments/lab-05-replication/data/MO_SNAP_Households/MO_SNAP_Households.shp rename to assignments/lab-2-2-replication/data/MO_SNAP_Households/MO_SNAP_Households.shp diff --git a/assignments/lab-05-replication/data/MO_SNAP_Households/MO_SNAP_Households.shx b/assignments/lab-2-2-replication/data/MO_SNAP_Households/MO_SNAP_Households.shx similarity index 100% rename from assignments/lab-05-replication/data/MO_SNAP_Households/MO_SNAP_Households.shx rename to assignments/lab-2-2-replication/data/MO_SNAP_Households/MO_SNAP_Households.shx diff --git a/assignments/lab-05-replication/data/STL_SNAP_Households/STL_SNAP_Households.dbf b/assignments/lab-2-2-replication/data/STL_SNAP_Households/STL_SNAP_Households.dbf similarity index 100% rename from assignments/lab-05-replication/data/STL_SNAP_Households/STL_SNAP_Households.dbf rename to assignments/lab-2-2-replication/data/STL_SNAP_Households/STL_SNAP_Households.dbf diff --git a/assignments/lab-05-replication/data/STL_SNAP_Households/STL_SNAP_Households.prj b/assignments/lab-2-2-replication/data/STL_SNAP_Households/STL_SNAP_Households.prj similarity index 100% rename from assignments/lab-05-replication/data/STL_SNAP_Households/STL_SNAP_Households.prj rename to assignments/lab-2-2-replication/data/STL_SNAP_Households/STL_SNAP_Households.prj diff --git a/assignments/lab-05-replication/data/STL_SNAP_Households/STL_SNAP_Households.shp b/assignments/lab-2-2-replication/data/STL_SNAP_Households/STL_SNAP_Households.shp similarity index 100% rename from assignments/lab-05-replication/data/STL_SNAP_Households/STL_SNAP_Households.shp rename to assignments/lab-2-2-replication/data/STL_SNAP_Households/STL_SNAP_Households.shp diff --git a/assignments/lab-05-replication/data/STL_SNAP_Households/STL_SNAP_Households.shx b/assignments/lab-2-2-replication/data/STL_SNAP_Households/STL_SNAP_Households.shx similarity index 100% rename from assignments/lab-05-replication/data/STL_SNAP_Households/STL_SNAP_Households.shx rename to assignments/lab-2-2-replication/data/STL_SNAP_Households/STL_SNAP_Households.shx diff --git a/assignments/lab-05-replication/docs/lab-05.Rmd b/assignments/lab-2-2-replication/docs/lab-2-2.Rmd similarity index 94% rename from assignments/lab-05-replication/docs/lab-05.Rmd rename to assignments/lab-2-2-replication/docs/lab-2-2.Rmd index 566a289..65c6ab2 100644 --- a/assignments/lab-05-replication/docs/lab-05.Rmd +++ b/assignments/lab-2-2-replication/docs/lab-2-2.Rmd @@ -1,10 +1,11 @@ --- -title: "Lab-05 Replication Notebook" +title: "Lab 2-2 Replication Notebook" author: "Christopher Prener, Ph.D." date: '(`r format(Sys.time(), "%B %d, %Y")`)' output: github_document: default html_notebook: default +always_allow_html: true --- ```{r setup} @@ -12,7 +13,7 @@ knitr::opts_chunk$set(cache = FALSE) ``` ## Introduction -This is the replication notebook for Lab-05 from the course SOC 4650/5650: Introduction to GISc. +This is the replication notebook for Lab 2-2 from the course SOC 4650/5650: Introduction to GISc. ## Load Dependencies The following code loads the package dependencies for our analysis: diff --git a/assignments/lab-2-2-replication/docs/lab-2-2.md b/assignments/lab-2-2-replication/docs/lab-2-2.md new file mode 100644 index 0000000..251d0f3 --- /dev/null +++ b/assignments/lab-2-2-replication/docs/lab-2-2.md @@ -0,0 +1,178 @@ +Lab 2-2 Replication Notebook +================ +Christopher Prener, Ph.D. +(February 21, 2022) + +``` r +knitr::opts_chunk$set(cache = FALSE) +``` + +## Introduction + +This is the replication notebook for Lab 2-2 from the course SOC +4650/5650: Introduction to GISc. + +## Load Dependencies + +The following code loads the package dependencies for our analysis: + +``` r +# tidyverse packages +library(dplyr) # data wrangling +``` + + ## + ## Attaching package: 'dplyr' + + ## The following objects are masked from 'package:stats': + ## + ## filter, lag + + ## The following objects are masked from 'package:base': + ## + ## intersect, setdiff, setequal, union + +``` r +# spatial packages +library(mapview) # preview spatial data +library(sf) # spatial data tools +``` + + ## Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1 + +``` r +library(tidycensus) # data wrangling +library(tigris) # data wrangling +``` + + ## To enable + ## caching of data, set `options(tigris_use_cache = TRUE)` in your R script or .Rprofile. + + ## + ## Attaching package: 'tigris' + + ## The following object is masked from 'package:tidycensus': + ## + ## fips_codes + +``` r +# other packages +library(here) # file path tools +``` + + ## here() starts at /Users/prenercg/GitHub/slu-soc5650/module-2-combine-sources/assignments/lab-2-2-replication + +## Part 1 + +### Question 1 + +First, we’ll download and preview the variables using the +`load_variables()` function from `tidycensus`. + +``` r +acs <- load_variables(2019, "acs5", cache = TRUE) +``` + +The variables we need represent: + +- `"PUBLIC ASSISTANCE INCOME OR FOOD STAMPS/SNAP IN THE PAST 12 MONTHS FOR HOUSEHOLDS"` +- `"MEDICAID/MEANS-TESTED PUBLIC COVERAGE BY SEX BY AGE"` + +### Question 2 + +First, we’ll download the relevant ACS data using `get_acs()`. We get +the data for all counties by specifying `"county"` as the geography: + +``` r +snapCounties <- get_acs(geography = "county", year = 2019, state = 29, + variables = c("B19058_001", "B19058_002"), + output = "wide", geometry = TRUE) +``` + + ## Getting data from the 2015-2019 5-year ACS + + ## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`. + + ## | | | 0% | | | 1% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |== | 4% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 10% | |======= | 11% | |======== | 11% | |======== | 12% | |========= | 13% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 17% | |============ | 18% | |============= | 18% | |============= | 19% | |============== | 20% | |=============== | 21% | |=============== | 22% | |================ | 23% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |=================== | 27% | |====================== | 31% | |======================= | 33% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 37% | |============================ | 40% | |============================= | 41% | |============================= | 42% | |============================== | 42% | |============================== | 43% | |============================== | 44% | |=============================== | 44% | |=============================== | 45% | |================================ | 45% | |================================ | 46% | |================================= | 47% | |================================= | 48% | |================================== | 48% | |================================== | 49% | |=================================== | 49% | |=================================== | 50% | |==================================== | 51% | |==================================== | 52% | |===================================== | 52% | |===================================== | 53% | |====================================== | 54% | |====================================== | 55% | |======================================= | 55% | |======================================= | 56% | |======================================== | 56% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 59% | |========================================== | 60% | |========================================== | 61% | |=========================================== | 61% | |============================================= | 64% | |====================================================== | 78% | |================================================================ | 92% | |=================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |===================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 100% + +We can preview our geometric data with `mapview`: + +``` r +mapview(snapCounties) +``` + + ## PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable. + +
+ + +### Question 3 + +Next, we’ll clean our data by renaming variables: + +``` r +snapCounties %>% + rename( + total_pop = B19058_001E, + total_pop_moe = B19058_001M, + snap = B19058_002E, + snap_moe = B19058_002M + ) -> snapCounties +``` + +## Part 2 + +### Question 4 + +Next, we’ll download the relevant ACS data for Medicaid using +`get_acs()`: + +``` r +medicaidCounties <- get_acs(geography = "county", year = 2019, state = 29, + variables = c("C27007_002", "C27007_012"), + output = "wide", geometry = FALSE) +``` + + ## Getting data from the 2015-2019 5-year ACS + +Now we have the number of male and female Medicaid recipients. + +### Question 5 + +Next, we’ll tidy up the demographic data, including by renaming +variables and summing our male and female Medicaid estimates: + +``` r +medicaidCounties %>% + rename( + medicaid_male = C27007_002E, + medicaid_male_moe = C27007_002M, + medicaid_female = C27007_012E, + medicaid_female_moe = C27007_012M + ) %>% + mutate(medicaid = medicaid_male + medicaid_female) %>% + select(-NAME) -> medicaidCounties +``` + +Now our data are ready to join with our SNAP recipiency data! + +## Part 3 + +### Question 6 + +Finally, we’ll combine our data: + +``` r +services <- left_join(snapCounties, medicaidCounties, by = "GEOID") +``` + +To make sure things went correctly, we’ll preview our data again: + +``` r +mapview(services, zcol = "medicaid") +``` + +
+ + +Our data map correctly! diff --git a/assignments/lab-05-replication/docs/lab-05.nb.html b/assignments/lab-2-2-replication/docs/lab-2-2.nb.html similarity index 83% rename from assignments/lab-05-replication/docs/lab-05.nb.html rename to assignments/lab-2-2-replication/docs/lab-2-2.nb.html index 96258cb..08feed4 100644 --- a/assignments/lab-05-replication/docs/lab-05.nb.html +++ b/assignments/lab-2-2-replication/docs/lab-2-2.nb.html @@ -12,19 +12,28 @@ -Lab-05 Replication Notebook +Lab 2-2 Replication Notebook - + + - + @@ -39,11 +48,6 @@ - @@ -438,7 +416,7 @@

Question 6

diff --git a/assignments/lab-05-replication/lab-05-replication.Rproj b/assignments/lab-2-2-replication/lab-2-2-replication.Rproj similarity index 100% rename from assignments/lab-05-replication/lab-05-replication.Rproj rename to assignments/lab-2-2-replication/lab-2-2-replication.Rproj diff --git a/assignments/lab-05.pdf b/assignments/lab-2-2.pdf similarity index 58% rename from assignments/lab-05.pdf rename to assignments/lab-2-2.pdf index ee7fe1f..cc53b07 100644 Binary files a/assignments/lab-05.pdf and b/assignments/lab-2-2.pdf differ diff --git a/docs/index.nb.html b/docs/index.nb.html index a35a4bf..130fb1d 100644 --- a/docs/index.nb.html +++ b/docs/index.nb.html @@ -15,19 +15,44 @@ Meeting Examples - Complete - + + - + + + + + + + + + + + + + + + + + - + +

We rarely want to download these one at a time. Instead, we want to download them at one time into a single data frame. The table number for these data is P003 - we take the first four characters from the name variable.

+ +
cityRace00 <- get_decennial(geography = "tract", year = 2000, state = 29,
+                            county = "510", table = "P003", output = "wide")
+

We’ve used the FIPS codes for both Missouri (29) and St. Louis City (29510) here - you can find a full list of Missouri counties here.

@@ -323,6 +371,201 @@

Add Geometry

The tidycensus package also includes tools for downloading the geometries for these data as well. For instance, we can add geometric data to our previous call for City of St. Louis tract-level data on race by adding the geometry = TRUE argument:

+ +
## download
+cityRace00 <- get_decennial(geography = "tract", year = 2000, state = 29,
+                            county = "510", table = "P003", output = "wide",
+                            geometry = TRUE)
+ + +
Getting data from the 2000 decennial Census
+Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
+Loading SF1 variables for 2000 from table P003. To cache this dataset for faster access to Census tables in the future, run this function with `cache_table = TRUE`. You only need to do this once per Census dataset.
+Using Census Summary File 1
+Using Census Summary File 1
+ + +

+  |                                                                                                                                                         
+  |                                                                                                                                                   |   0%
+  |                                                                                                                                                         
+  |==                                                                                                                                                 |   1%
+  |                                                                                                                                                         
+  |===                                                                                                                                                |   2%
+  |                                                                                                                                                         
+  |====                                                                                                                                               |   3%
+  |                                                                                                                                                         
+  |=====                                                                                                                                              |   3%
+  |                                                                                                                                                         
+  |=====                                                                                                                                              |   4%
+  |                                                                                                                                                         
+  |======                                                                                                                                             |   4%
+  |                                                                                                                                                         
+  |=======                                                                                                                                            |   5%
+  |                                                                                                                                                         
+  |========                                                                                                                                           |   5%
+  |                                                                                                                                                         
+  |=========                                                                                                                                          |   6%
+  |                                                                                                                                                         
+  |==========                                                                                                                                         |   7%
+  |                                                                                                                                                         
+  |===========                                                                                                                                        |   7%
+  |                                                                                                                                                         
+  |===========                                                                                                                                        |   8%
+  |                                                                                                                                                         
+  |============                                                                                                                                       |   8%
+  |                                                                                                                                                         
+  |=============                                                                                                                                      |   9%
+  |                                                                                                                                                         
+  |==============                                                                                                                                     |   9%
+  |                                                                                                                                                         
+  |==============                                                                                                                                     |  10%
+  |                                                                                                                                                         
+  |===============                                                                                                                                    |  10%
+  |                                                                                                                                                         
+  |================                                                                                                                                   |  11%
+  |                                                                                                                                                         
+  |=================                                                                                                                                  |  11%
+  |                                                                                                                                                         
+  |=================                                                                                                                                  |  12%
+  |                                                                                                                                                         
+  |==================                                                                                                                                 |  12%
+  |                                                                                                                                                         
+  |==================                                                                                                                                 |  13%
+  |                                                                                                                                                         
+  |===================                                                                                                                                |  13%
+  |                                                                                                                                                         
+  |====================                                                                                                                               |  13%
+  |                                                                                                                                                         
+  |====================                                                                                                                               |  14%
+  |                                                                                                                                                         
+  |======================                                                                                                                             |  15%
+  |                                                                                                                                                         
+  |=======================                                                                                                                            |  16%
+  |                                                                                                                                                         
+  |========================                                                                                                                           |  16%
+  |                                                                                                                                                         
+  |==========================                                                                                                                         |  17%
+  |                                                                                                                                                         
+  |===========================                                                                                                                        |  19%
+  |                                                                                                                                                         
+  |=============================                                                                                                                      |  20%
+  |                                                                                                                                                         
+  |===============================                                                                                                                    |  21%
+  |                                                                                                                                                         
+  |=================================                                                                                                                  |  22%
+  |                                                                                                                                                         
+  |==================================                                                                                                                 |  23%
+  |                                                                                                                                                         
+  |====================================                                                                                                               |  25%
+  |                                                                                                                                                         
+  |======================================                                                                                                             |  26%
+  |                                                                                                                                                         
+  |========================================                                                                                                           |  27%
+  |                                                                                                                                                         
+  |==========================================                                                                                                         |  28%
+  |                                                                                                                                                         
+  |============================================                                                                                                       |  30%
+  |                                                                                                                                                         
+  |==============================================                                                                                                     |  31%
+  |                                                                                                                                                         
+  |===============================================                                                                                                    |  32%
+  |                                                                                                                                                         
+  |================================================                                                                                                   |  32%
+  |                                                                                                                                                         
+  |=================================================                                                                                                  |  33%
+  |                                                                                                                                                         
+  |===================================================                                                                                                |  35%
+  |                                                                                                                                                         
+  |====================================================                                                                                               |  36%
+  |                                                                                                                                                         
+  |=======================================================                                                                                            |  37%
+  |                                                                                                                                                         
+  |========================================================                                                                                           |  38%
+  |                                                                                                                                                         
+  |==========================================================                                                                                         |  40%
+  |                                                                                                                                                         
+  |============================================================                                                                                       |  41%
+  |                                                                                                                                                         
+  |===============================================================                                                                                    |  43%
+  |                                                                                                                                                         
+  |===================================================================                                                                                |  45%
+  |                                                                                                                                                         
+  |=====================================================================                                                                              |  47%
+  |                                                                                                                                                         
+  |======================================================================                                                                             |  48%
+  |                                                                                                                                                         
+  |=========================================================================                                                                          |  49%
+  |                                                                                                                                                         
+  |==========================================================================                                                                         |  50%
+  |                                                                                                                                                         
+  |==============================================================================                                                                     |  53%
+  |                                                                                                                                                         
+  |=================================================================================                                                                  |  55%
+  |                                                                                                                                                         
+  |====================================================================================                                                               |  57%
+  |                                                                                                                                                         
+  |=====================================================================================                                                              |  58%
+  |                                                                                                                                                         
+  |=======================================================================================                                                            |  59%
+  |                                                                                                                                                         
+  |===========================================================================================                                                        |  62%
+  |                                                                                                                                                         
+  |============================================================================================                                                       |  63%
+  |                                                                                                                                                         
+  |================================================================================================                                                   |  65%
+  |                                                                                                                                                         
+  |==================================================================================================                                                 |  67%
+  |                                                                                                                                                         
+  |===================================================================================================                                                |  67%
+  |                                                                                                                                                         
+  |=======================================================================================================                                            |  70%
+  |                                                                                                                                                         
+  |==========================================================================================================                                         |  72%
+  |                                                                                                                                                         
+  |==============================================================================================================                                     |  75%
+  |                                                                                                                                                         
+  |=================================================================================================================                                  |  77%
+  |                                                                                                                                                         
+  |====================================================================================================================                               |  79%
+  |                                                                                                                                                         
+  |=====================================================================================================================                              |  80%
+  |                                                                                                                                                         
+  |=======================================================================================================================                            |  81%
+  |                                                                                                                                                         
+  |=========================================================================================================================                          |  82%
+  |                                                                                                                                                         
+  |===========================================================================================================================                        |  84%
+  |                                                                                                                                                         
+  |============================================================================================================================                       |  84%
+  |                                                                                                                                                         
+  |================================================================================================================================                   |  87%
+  |                                                                                                                                                         
+  |==================================================================================================================================                 |  89%
+  |                                                                                                                                                         
+  |=====================================================================================================================================              |  90%
+  |                                                                                                                                                         
+  |=========================================================================================================================================          |  93%
+  |                                                                                                                                                         
+  |==============================================================================================================================================     |  97%
+  |                                                                                                                                                         
+  |===================================================================================================================================================| 100%
+ + +
## preview
+mapview(cityRace00, zcol = "P003005")
+ + + + + +
+ + + + + +

Notice how I used the zcol argument for mapview() to preview a specific set of data as a thematic layer on the map! These data are not normalized, but we do get a quick preview of the distribution of Asian residents in St. Louis City.

@@ -335,6 +578,9 @@

Get List of Variables

To get a preview of variables available in the get_acs() function, we can use the load_variables() function again. We’ll use "acs5" for our dataset and, for this example, we’ll pull from the most recent 2019 ACS year:

+ +
census <- load_variables(year = 2019, dataset = "acs5") 
+

Try searching for the table B19013, the median household income table.

@@ -344,12 +590,257 @@

Get and Interpret ACS Data

We’ll illustrate get_acs() by using the data in table B19019. First, we’ll download these data as a full table for all counties in Missouri:

+ +
## download
+countyIncome <- get_acs(geography = "county", year = 2019, state = 29,
+                        table = "B19019", output = "wide", geometry = TRUE)
+ + +
Getting data from the 2015-2019 5-year ACS
+Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
+Loading ACS5 variables for 2019 from table B19019. To cache this dataset for faster access to ACS tables in the future, run this function with `cache_table = TRUE`. You only need to do this once per ACS dataset.
+ + +

+  |                                                                                                                                                         
+  |                                                                                                                                                   |   0%
+  |                                                                                                                                                         
+  |=                                                                                                                                                  |   1%
+  |                                                                                                                                                         
+  |===                                                                                                                                                |   2%
+  |                                                                                                                                                         
+  |====                                                                                                                                               |   2%
+  |                                                                                                                                                         
+  |=====                                                                                                                                              |   3%
+  |                                                                                                                                                         
+  |======                                                                                                                                             |   4%
+  |                                                                                                                                                         
+  |=======                                                                                                                                            |   5%
+  |                                                                                                                                                         
+  |=========                                                                                                                                          |   6%
+  |                                                                                                                                                         
+  |==========                                                                                                                                         |   7%
+  |                                                                                                                                                         
+  |===========                                                                                                                                        |   7%
+  |                                                                                                                                                         
+  |============                                                                                                                                       |   8%
+  |                                                                                                                                                         
+  |=============                                                                                                                                      |   9%
+  |                                                                                                                                                         
+  |==============                                                                                                                                     |   9%
+  |                                                                                                                                                         
+  |==============                                                                                                                                     |  10%
+  |                                                                                                                                                         
+  |===============                                                                                                                                    |  10%
+  |                                                                                                                                                         
+  |===============                                                                                                                                    |  11%
+  |                                                                                                                                                         
+  |=================                                                                                                                                  |  12%
+  |                                                                                                                                                         
+  |==================                                                                                                                                 |  12%
+  |                                                                                                                                                         
+  |===================                                                                                                                                |  13%
+  |                                                                                                                                                         
+  |====================                                                                                                                               |  13%
+  |                                                                                                                                                         
+  |====================                                                                                                                               |  14%
+  |                                                                                                                                                         
+  |======================                                                                                                                             |  15%
+  |                                                                                                                                                         
+  |=======================                                                                                                                            |  16%
+  |                                                                                                                                                         
+  |========================                                                                                                                           |  16%
+  |                                                                                                                                                         
+  |=========================                                                                                                                          |  17%
+  |                                                                                                                                                         
+  |==========================                                                                                                                         |  18%
+  |                                                                                                                                                         
+  |===========================                                                                                                                        |  18%
+  |                                                                                                                                                         
+  |============================                                                                                                                       |  19%
+  |                                                                                                                                                         
+  |=============================                                                                                                                      |  20%
+  |                                                                                                                                                         
+  |==============================                                                                                                                     |  20%
+  |                                                                                                                                                         
+  |===============================                                                                                                                    |  21%
+  |                                                                                                                                                         
+  |=================================                                                                                                                  |  23%
+  |                                                                                                                                                         
+  |==================================                                                                                                                 |  23%
+  |                                                                                                                                                         
+  |====================================                                                                                                               |  25%
+  |                                                                                                                                                         
+  |=====================================                                                                                                              |  25%
+  |                                                                                                                                                         
+  |======================================                                                                                                             |  26%
+  |                                                                                                                                                         
+  |=======================================                                                                                                            |  26%
+  |                                                                                                                                                         
+  |=========================================                                                                                                          |  28%
+  |                                                                                                                                                         
+  |===========================================                                                                                                        |  29%
+  |                                                                                                                                                         
+  |==============================================                                                                                                     |  31%
+  |                                                                                                                                                         
+  |=================================================                                                                                                  |  33%
+  |                                                                                                                                                         
+  |===================================================                                                                                                |  35%
+  |                                                                                                                                                         
+  |====================================================                                                                                               |  35%
+  |                                                                                                                                                         
+  |=====================================================                                                                                              |  36%
+  |                                                                                                                                                         
+  |=======================================================                                                                                            |  38%
+  |                                                                                                                                                         
+  |=========================================================                                                                                          |  39%
+  |                                                                                                                                                         
+  |============================================================                                                                                       |  41%
+  |                                                                                                                                                         
+  |=============================================================                                                                                      |  42%
+  |                                                                                                                                                         
+  |===============================================================                                                                                    |  43%
+  |                                                                                                                                                         
+  |===================================================================                                                                                |  45%
+  |                                                                                                                                                         
+  |=====================================================================                                                                              |  47%
+  |                                                                                                                                                         
+  |=======================================================================                                                                            |  48%
+  |                                                                                                                                                         
+  |=========================================================================                                                                          |  49%
+  |                                                                                                                                                         
+  |==========================================================================                                                                         |  51%
+  |                                                                                                                                                         
+  |===========================================================================                                                                        |  51%
+  |                                                                                                                                                         
+  |=============================================================================                                                                      |  52%
+  |                                                                                                                                                         
+  |==============================================================================                                                                     |  53%
+  |                                                                                                                                                         
+  |===============================================================================                                                                    |  53%
+  |                                                                                                                                                         
+  |===============================================================================                                                                    |  54%
+  |                                                                                                                                                         
+  |================================================================================                                                                   |  54%
+  |                                                                                                                                                         
+  |=================================================================================                                                                  |  55%
+  |                                                                                                                                                         
+  |===================================================================================                                                                |  56%
+  |                                                                                                                                                         
+  |====================================================================================                                                               |  57%
+  |                                                                                                                                                         
+  |======================================================================================                                                             |  59%
+  |                                                                                                                                                         
+  |=======================================================================================                                                            |  59%
+  |                                                                                                                                                         
+  |=========================================================================================                                                          |  61%
+  |                                                                                                                                                         
+  |==========================================================================================                                                         |  61%
+  |                                                                                                                                                         
+  |===========================================================================================                                                        |  62%
+  |                                                                                                                                                         
+  |============================================================================================                                                       |  62%
+  |                                                                                                                                                         
+  |============================================================================================                                                       |  63%
+  |                                                                                                                                                         
+  |=============================================================================================                                                      |  63%
+  |                                                                                                                                                         
+  |===============================================================================================                                                    |  65%
+  |                                                                                                                                                         
+  |=================================================================================================                                                  |  66%
+  |                                                                                                                                                         
+  |===================================================================================================                                                |  68%
+  |                                                                                                                                                         
+  |=====================================================================================================                                              |  69%
+  |                                                                                                                                                         
+  |=======================================================================================================                                            |  70%
+  |                                                                                                                                                         
+  |=========================================================================================================                                          |  71%
+  |                                                                                                                                                         
+  |===========================================================================================================                                        |  73%
+  |                                                                                                                                                         
+  |=============================================================================================================                                      |  74%
+  |                                                                                                                                                         
+  |==============================================================================================================                                     |  75%
+  |                                                                                                                                                         
+  |=================================================================================================================                                  |  77%
+  |                                                                                                                                                         
+  |====================================================================================================================                               |  79%
+  |                                                                                                                                                         
+  |======================================================================================================================                             |  81%
+  |                                                                                                                                                         
+  |========================================================================================================================                           |  81%
+  |                                                                                                                                                         
+  |===========================================================================================================================                        |  84%
+  |                                                                                                                                                         
+  |=============================================================================================================================                      |  85%
+  |                                                                                                                                                         
+  |===============================================================================================================================                    |  87%
+  |                                                                                                                                                         
+  |=================================================================================================================================                  |  88%
+  |                                                                                                                                                         
+  |===================================================================================================================================                |  89%
+  |                                                                                                                                                         
+  |=====================================================================================================================================              |  90%
+  |                                                                                                                                                         
+  |=======================================================================================================================================            |  92%
+  |                                                                                                                                                         
+  |==========================================================================================================================================         |  94%
+  |                                                                                                                                                         
+  |=============================================================================================================================================      |  96%
+  |                                                                                                                                                         
+  |================================================================================================================================================   |  98%
+  |                                                                                                                                                         
+  |================================================================================================================================================== |  99%
+  |                                                                                                                                                         
+  |===================================================================================================================================================| 100%
+ + +
## preview
+mapview(countyIncome, zcol = "B19019_001E")
+ + + + + +
+ + + + + +

Notice how we needed to specify _001E for zcol. That references the specific variable we want to map - variable 1 in the table’s estimate (or E). The M values refer to the margin of the error - we expect this estimate to be off by some amount within +/- this value.

We can also download a specific column, like the median income for one-person households (B19019_002):

+ +
## download
+countyIncome <- get_acs(geography = "county", year = 2019, state = 29,
+                        variables = "B19019_002", output = "wide", 
+                        geometry = TRUE)
+ + +
Getting data from the 2015-2019 5-year ACS
+Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
+ + +
## preview
+mapview(countyIncome, zcol = "B19019_002E")
+ + + + + +
+ + + + + + @@ -359,11 +850,46 @@

Combining Data Sources

Perhaps we have a range of data that we want to include. For this example, we’ll download data on median income and the proportion of women in tracts in Boone County, Missouri. We’ll download the income data with geometry = TRUE and the sex data with geometry = FALSE:

+ +
## download
+booneIncome <- get_acs(geography = "tract", year = 2019, state = 29,
+                       county = "019", variables = "B19019_001", 
+                       output = "wide", geometry = TRUE) %>%
+  rename(median_income = B19019_001E) %>%
+  select(GEOID, median_income)
+ + +
Getting data from the 2015-2019 5-year ACS
+Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
+ + +

+  |                                                                                                                                                         
+  |                                                                                                                                                   |   0%
+  |                                                                                                                                                         
+  |========================                                                                                                                           |  17%
+  |                                                                                                                                                         
+  |===================================================================================================================================================| 100%
+ + +
## download
+booneSex <- get_acs(geography = "tract", year = 2019, state = 29,
+                       county = "019", variables = c("B01001_001", "B01001_026"),
+                       output = "wide") %>%
+  mutate(pct_women = B01001_026E/B01001_001E*100) %>%
+  select(GEOID, pct_women)
+ + +
Getting data from the 2015-2019 5-year ACS
+

To combine these data, we’ll use left_join() from dplyr. Our sf object should always be the first object in the join (the x data) and our non-sf data should be the second data (the y data):

+ +
boone <- left_join(booneIncome, booneSex, by = "GEOID")
+

Three common issues arise:

@@ -381,6 +907,18 @@

State Data

We can download a generalized version, which smooths out state boundaries so that the overall image is both smaller in disk size and (sometimes) easier to read. This is particularly helpful if you are making small scale maps of the entire United States. We’ll get these data at the “20m” resolution using the states() function:

+ +
states <- states(cb = TRUE, resolution = "20m")
+ + +

+  |                                                                                                                                                         
+  |                                                                                                                                                   |   0%
+  |                                                                                                                                                         
+  |================================================================================================================================                   |  87%
+  |                                                                                                                                                         
+  |===================================================================================================================================================| 100%
+ @@ -389,6 +927,32 @@

County Data

Now, we’ll get more detailed data - all of the county boundaries for Missouri. We’ll use the counties() function using a slightly less generalized resolution, “5m”:

+ +
moCounties <- counties(cb = TRUE, resolution = "5m")
+ + +

+  |                                                                                                                                                         
+  |                                                                                                                                                   |   0%
+  |                                                                                                                                                         
+  |==                                                                                                                                                 |   1%
+  |                                                                                                                                                         
+  |==========================                                                                                                                         |  18%
+  |                                                                                                                                                         
+  |==============================================                                                                                                     |  32%
+  |                                                                                                                                                         
+  |==============================================================                                                                                     |  42%
+  |                                                                                                                                                         
+  |========================================================================                                                                           |  49%
+  |                                                                                                                                                         
+  |===========================================================================                                                                        |  51%
+  |                                                                                                                                                         
+  |===================================================================================================                                                |  67%
+  |                                                                                                                                                         
+  |====================================================================================================                                               |  68%
+  |                                                                                                                                                         
+  |===================================================================================================================================================| 100%
+ @@ -397,13 +961,147 @@

Tract Data

Now, we’ll get even more detailed data - all of the tract boundaries for St. Charles County, Missouri. We’ll use the tracts() function with cb = FALSE by default:

+ +
stCharlesTracts <- tracts(state = 29, county = 183)
+ + +

+  |                                                                                                                                                         
+  |                                                                                                                                                   |   0%
+  |                                                                                                                                                         
+  |=                                                                                                                                                  |   1%
+  |                                                                                                                                                         
+  |==========                                                                                                                                         |   7%
+  |                                                                                                                                                         
+  |==============                                                                                                                                     |   9%
+  |                                                                                                                                                         
+  |===============                                                                                                                                    |  10%
+  |                                                                                                                                                         
+  |================                                                                                                                                   |  11%
+  |                                                                                                                                                         
+  |=================                                                                                                                                  |  11%
+  |                                                                                                                                                         
+  |===================                                                                                                                                |  13%
+  |                                                                                                                                                         
+  |=====================                                                                                                                              |  14%
+  |                                                                                                                                                         
+  |======================                                                                                                                             |  15%
+  |                                                                                                                                                         
+  |===========================                                                                                                                        |  19%
+  |                                                                                                                                                         
+  |===============================                                                                                                                    |  21%
+  |                                                                                                                                                         
+  |=================================                                                                                                                  |  22%
+  |                                                                                                                                                         
+  |=================================                                                                                                                  |  23%
+  |                                                                                                                                                         
+  |=====================================                                                                                                              |  25%
+  |                                                                                                                                                         
+  |======================================                                                                                                             |  26%
+  |                                                                                                                                                         
+  |===========================================                                                                                                        |  29%
+  |                                                                                                                                                         
+  |===============================================                                                                                                    |  32%
+  |                                                                                                                                                         
+  |================================================                                                                                                   |  32%
+  |                                                                                                                                                         
+  |================================================                                                                                                   |  33%
+  |                                                                                                                                                         
+  |==================================================                                                                                                 |  34%
+  |                                                                                                                                                         
+  |======================================================                                                                                             |  36%
+  |                                                                                                                                                         
+  |========================================================                                                                                           |  38%
+  |                                                                                                                                                         
+  |=========================================================                                                                                          |  39%
+  |                                                                                                                                                         
+  |==============================================================                                                                                     |  42%
+  |                                                                                                                                                         
+  |===============================================================                                                                                    |  43%
+  |                                                                                                                                                         
+  |==================================================================                                                                                 |  45%
+  |                                                                                                                                                         
+  |====================================================================                                                                               |  46%
+  |                                                                                                                                                         
+  |======================================================================                                                                             |  48%
+  |                                                                                                                                                         
+  |=========================================================================                                                                          |  49%
+  |                                                                                                                                                         
+  |=============================================================================                                                                      |  52%
+  |                                                                                                                                                         
+  |=============================================================================                                                                      |  53%
+  |                                                                                                                                                         
+  |================================================================================                                                                   |  54%
+  |                                                                                                                                                         
+  |================================================================================                                                                   |  55%
+  |                                                                                                                                                         
+  |=================================================================================                                                                  |  55%
+  |                                                                                                                                                         
+  |===================================================================================                                                                |  56%
+  |                                                                                                                                                         
+  |===================================================================================                                                                |  57%
+  |                                                                                                                                                         
+  |====================================================================================                                                               |  57%
+  |                                                                                                                                                         
+  |=====================================================================================                                                              |  58%
+  |                                                                                                                                                         
+  |========================================================================================                                                           |  60%
+  |                                                                                                                                                         
+  |=========================================================================================                                                          |  60%
+  |                                                                                                                                                         
+  |=========================================================================================                                                          |  61%
+  |                                                                                                                                                         
+  |===========================================================================================                                                        |  62%
+  |                                                                                                                                                         
+  |============================================================================================                                                       |  62%
+  |                                                                                                                                                         
+  |==============================================================================================                                                     |  64%
+  |                                                                                                                                                         
+  |=================================================================================================                                                  |  66%
+  |                                                                                                                                                         
+  |===================================================================================================                                                |  68%
+  |                                                                                                                                                         
+  |======================================================================================================                                             |  70%
+  |                                                                                                                                                         
+  |=========================================================================================================                                          |  72%
+  |                                                                                                                                                         
+  |===========================================================================================================                                        |  73%
+  |                                                                                                                                                         
+  |=============================================================================================================                                      |  74%
+  |                                                                                                                                                         
+  |=================================================================================================================                                  |  77%
+  |                                                                                                                                                         
+  |====================================================================================================================                               |  79%
+  |                                                                                                                                                         
+  |=======================================================================================================================                            |  81%
+  |                                                                                                                                                         
+  |==========================================================================================================================                         |  83%
+  |                                                                                                                                                         
+  |=============================================================================================================================                      |  85%
+  |                                                                                                                                                         
+  |===============================================================================================================================                    |  86%
+  |                                                                                                                                                         
+  |================================================================================================================================                   |  87%
+  |                                                                                                                                                         
+  |===================================================================================================================================                |  89%
+  |                                                                                                                                                         
+  |=====================================================================================================================================              |  91%
+  |                                                                                                                                                         
+  |=========================================================================================================================================          |  93%
+  |                                                                                                                                                         
+  |============================================================================================================================================       |  95%
+  |                                                                                                                                                         
+  |=================================================================================================================================================  |  99%
+  |                                                                                                                                                         
+  |===================================================================================================================================================| 100%
+ -
LS0tCnRpdGxlOiAiTWVldGluZyBFeGFtcGxlcyAtIENvbXBsZXRlIgphdXRob3I6ICJDaHJpc3RvcGhlciBQcmVuZXIsIFBoRCIKZGF0ZTogJyhgciBmb3JtYXQoU3lzLnRpbWUoKSwgIiVCICVkLCAlWSIpYCknCm91dHB1dDogCiAgZ2l0aHViX2RvY3VtZW50OiBkZWZhdWx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GZ1bmN0aW9uIHVzaW5nIGEgc2xpZ2h0bHkgbGVzcyBnZW5lcmFsaXplZCByZXNvbHV0aW9uLCAiNW0iOgoKYGBge3IgZ2V0LWNvdW50aWVzfQptb0NvdW50aWVzIDwtIGNvdW50aWVzKGNiID0gVFJVRSwgcmVzb2x1dGlvbiA9ICI1bSIpCmBgYAoKIyMjIFRyYWN0IERhdGEKTm93LCB3ZSdsbCBnZXQgZXZlbiBtb3JlIGRldGFpbGVkIGRhdGEgLSBhbGwgb2YgdGhlIHRyYWN0IGJvdW5kYXJpZXMgZm9yIFN0LiBDaGFybGVzIENvdW50eSwgTWlzc291cmkuIFdlJ2xsIHVzZSB0aGUgYHRyYWN0cygpYCBmdW5jdGlvbiB3aXRoIGBjYiA9IEZBTFNFYCBieSBkZWZhdWx0OgoKYGBge3IgZ2V0LXRyYWN0c30Kc3RDaGFybGVzVHJhY3RzIDwtIHRyYWN0cyhzdGF0ZSA9IDI5LCBjb3VudHkgPSAxODMpCmBgYAoKYGBge3IgbW92ZS10by1kb2NzLCBpbmNsdWRlPUZBTFNFfQojIHlvdSBkbyBuZWVkIHRvIGluY2x1ZGUgdGhpcyBpbiBhbnkgbm90ZWJvb2sgeW91IGNyZWF0ZSBmb3IgdGhpcyBjbGFzcwpmczo6ZmlsZV9jb3B5KGhlcmU6OmhlcmUoImV4YW1wbGVzIiwgIm1lZXRpbmctMi0yLWV4YW1wbGVzLWNvbXBsZXRlLm5iLmh0bWwiKSwgCiAgICAgICAgICAgICAgaGVyZTo6aGVyZSgiZG9jcyIsICJpbmRleC5uYi5odG1sIiksIAogICAgICAgICAgICAgIG92ZXJ3cml0ZSA9IFRSVUUpCmBgYA==
@@ -442,7 +1140,7 @@

Tract Data

$(document).ready(function () { $('.tabset-dropdown > .nav-tabs > li').click(function () { - $(this).parent().toggleClass('nav-tabs-open') + $(this).parent().toggleClass('nav-tabs-open'); }); }); @@ -450,7 +1148,7 @@

Tract Data

diff --git a/examples/module-examples-complete.Rmd b/examples/meeting-2-2-examples-complete.Rmd similarity index 98% rename from examples/module-examples-complete.Rmd rename to examples/meeting-2-2-examples-complete.Rmd index 587ef18..ddbb08b 100644 --- a/examples/module-examples-complete.Rmd +++ b/examples/meeting-2-2-examples-complete.Rmd @@ -5,6 +5,7 @@ date: '(`r format(Sys.time(), "%B %d, %Y")`)' output: github_document: default html_notebook: default +always_allow_html: true --- ```{r setup} @@ -184,7 +185,7 @@ stCharlesTracts <- tracts(state = 29, county = 183) ```{r move-to-docs, include=FALSE} # you do need to include this in any notebook you create for this class -fs::file_copy(here::here("examples", "module-examples-complete.nb.html"), +fs::file_copy(here::here("examples", "meeting-2-2-examples-complete.nb.html"), here::here("docs", "index.nb.html"), overwrite = TRUE) ``` \ No newline at end of file diff --git a/examples/meeting-2-2-examples-complete.md b/examples/meeting-2-2-examples-complete.md new file mode 100644 index 0000000..122831b --- /dev/null +++ b/examples/meeting-2-2-examples-complete.md @@ -0,0 +1,342 @@ +Meeting Examples - Complete +================ +Christopher Prener, PhD +(February 21, 2022) + +``` r +knitr::opts_chunk$set(cache = FALSE) +``` + +## Introduction + +This notebook illustrates data access through both `tigris` and +`tidycensus` as well as joins using `dplyr`. + +## Dependencies + +This notebook requires the following packages: + +``` r +# tidyverse packages +library(dplyr) # data wrangling +``` + + ## + ## Attaching package: 'dplyr' + + ## The following objects are masked from 'package:stats': + ## + ## filter, lag + + ## The following objects are masked from 'package:base': + ## + ## intersect, setdiff, setequal, union + +``` r +# spatial packages +library(mapview) # preview geometric data +library(sf) # spatial tools +``` + + ## Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1 + +``` r +library(tidycensus) # demographic data +library(tigris) # tiger/line data +``` + + ## To enable + ## caching of data, set `options(tigris_use_cache = TRUE)` in your R script or .Rprofile. + + ## + ## Attaching package: 'tigris' + + ## The following object is masked from 'package:tidycensus': + ## + ## fips_codes + +``` r +# other packages +library(here) # file path management +``` + + ## here() starts at /Users/prenercg/GitHub/slu-soc5650/module-2-combine-sources + +## tidycensus Set-up + +Before using `tidycensus`, you need to install a census API key. Use the +syntax below, copied into your console, to install the key you received +via email. + +``` r +census_api_key("KEY", install = TRUE) +``` + +This is not a code chunk you will need in each notebook. As long as +`install = TRUE`, you will only have to do this once! + +## Decennial Census Data + +### Get List of Variables + +To get a preview of variables available in the `get_decennial()` +function, we can use the `load_variables()` function: + +``` r +census <- load_variables(year = 2000, dataset = "sf1") +``` + +I find it useful to assign the output of this function to an object so +that I can search through it. Try searching for the variable `P0010001`, +the total population of a geographic unit, in the `census` object. + +### Download a Single Variable + +To download data, we can use use the `get_decennial()` function to +access, for example, population by state in 2000: + +``` r +popStates <- get_decennial(geography = "state", year = 2000, variable = "P001001") +``` + + ## Getting data from the 2000 decennial Census + + ## Using Census Summary File 1 + +A full list of the geographies available in `tidycensus` can be found +[here](https://walker-data.com/tidycensus/articles/basic-usage.html#geography-in-tidycensus-1). + +### Download a Full Table + +Most variables in the decennial census are actually a part of a table. +There are individual variables, for example, for race: + +``` r +census %>% + filter(concept == "P3. RACE [8]") +``` + + ## # A tibble: 0 × 3 + ## # … with 3 variables: name , label , concept + +We rarely want to download these one at a time. Instead, we want to +download them at one time into a single data frame. The table number for +these data is `P003` - we take the first four characters from the `name` +variable. + +``` r +cityRace00 <- get_decennial(geography = "tract", year = 2000, state = 29, + county = "510", table = "P003", output = "wide") +``` + + ## Getting data from the 2000 decennial Census + + ## Loading SF1 variables for 2000 from table P003. To cache this dataset for faster access to Census tables in the future, run this function with `cache_table = TRUE`. You only need to do this once per Census dataset. + + ## Using Census Summary File 1 + ## Using Census Summary File 1 + +We’ve used the FIPS codes for both Missouri (`29`) and St. Louis City +(`29510`) here - you can find a full list of Missouri counties +[here](https://www.msdis.missouri.edu/resources/fips.html). + +### Add Geometry + +The `tidycensus` package also includes tools for downloading the +geometries for these data as well. For instance, we can add geometric +data to our previous call for City of St. Louis tract-level data on race +by adding the `geometry = TRUE` argument: + +``` r +## download +cityRace00 <- get_decennial(geography = "tract", year = 2000, state = 29, + county = "510", table = "P003", output = "wide", + geometry = TRUE) +``` + + ## Getting data from the 2000 decennial Census + + ## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`. + + ## Loading SF1 variables for 2000 from table P003. To cache this dataset for faster access to Census tables in the future, run this function with `cache_table = TRUE`. You only need to do this once per Census dataset. + + ## Using Census Summary File 1 + ## Using Census Summary File 1 + + ## | | | 0% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 7% | |====== | 8% | |====== | 9% | |======= | 10% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 17% | |============= | 18% | |============= | 19% | |============== | 20% | |=============== | 21% | |=============== | 22% | |================ | 22% | |================ | 23% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |=================== | 27% | |==================== | 28% | |===================== | 30% | |====================== | 32% | |======================== | 34% | |========================= | 36% | |=========================== | 39% | |============================ | 40% | |============================= | 42% | |============================== | 43% | |================================ | 45% | |================================= | 47% | |================================== | 48% | |=================================== | 50% | |==================================== | 52% | |===================================== | 53% | |====================================== | 55% | |======================================= | 56% | |========================================= | 58% | |========================================== | 60% | |=========================================== | 61% | |=========================================== | 62% | |============================================= | 64% | |=============================================== | 67% | |================================================ | 68% | |================================================= | 70% | |================================================== | 72% | |=================================================== | 73% | |==================================================== | 75% | |====================================================== | 77% | |======================================================= | 78% | |======================================================== | 80% | |========================================================= | 81% | |=========================================================== | 84% | |============================================================ | 85% | |============================================================= | 87% | |============================================================== | 88% | |=============================================================== | 89% | |================================================================ | 91% | |================================================================= | 94% | |================================================================== | 94% | |=================================================================== | 96% | |==================================================================== | 98% | |======================================================================| 100% + +``` r +## preview +mapview(cityRace00, zcol = "P003005") +``` + + ## PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable. + +
+ + +Notice how I used the `zcol` argument for `mapview()` to preview a +specific set of data as a thematic layer on the map! These data are not +normalized, but we do get a quick preview of the distribution of Asian +residents in St. Louis City. + +## Decennial Census Data + +### Get List of Variables + +To get a preview of variables available in the `get_acs()` function, we +can use the `load_variables()` function again. We’ll use `"acs5"` for +our dataset and, for this example, we’ll pull from the most recent 2019 +ACS year: + +``` r +census <- load_variables(year = 2019, dataset = "acs5") +``` + +Try searching for the table `B19013`, the median household income table. + +### Get and Interpret ACS Data + +We’ll illustrate `get_acs()` by using the data in table `B19019`. First, +we’ll download these data as a full table for all counties in Missouri: + +``` r +## download +countyIncome <- get_acs(geography = "county", year = 2019, state = 29, + table = "B19019", output = "wide", geometry = TRUE) +``` + + ## Getting data from the 2015-2019 5-year ACS + + ## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`. + + ## Loading ACS5 variables for 2019 from table B19019. To cache this dataset for faster access to ACS tables in the future, run this function with `cache_table = TRUE`. You only need to do this once per ACS dataset. + + ## | | | 0% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 7% | |====== | 8% | |====== | 9% | |======= | 10% | |======= | 11% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 16% | |============ | 17% | |============ | 18% | |============= | 18% | |============= | 19% | |============== | 20% | |=============== | 21% | |=============== | 22% | |================ | 22% | |================ | 23% | |================= | 24% | |================= | 25% | |================== | 25% | |==================== | 28% | |==================== | 29% | |===================== | 30% | |===================== | 31% | |====================== | 31% | |====================== | 32% | |======================= | 33% | |======================= | 34% | |======================== | 34% | |======================== | 35% | |========================= | 36% | |========================== | 37% | |========================== | 38% | |=========================== | 38% | |=========================== | 39% | |============================ | 39% | |============================ | 40% | |============================ | 41% | |============================= | 41% | |============================= | 42% | |============================== | 42% | |============================== | 43% | |=============================== | 44% | |=============================== | 45% | |================================ | 45% | |================================ | 46% | |================================= | 47% | |================================== | 48% | |================================== | 49% | |=================================== | 49% | |=================================== | 50% | |==================================== | 51% | |==================================== | 52% | |===================================== | 52% | |===================================== | 53% | |====================================== | 54% | |====================================== | 55% | |======================================= | 55% | |======================================= | 56% | |======================================== | 56% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 59% | |========================================== | 60% | |========================================== | 61% | |=========================================== | 61% | |=========================================== | 62% | |============================================ | 62% | |============================================ | 63% | |============================================ | 64% | |============================================= | 64% | |============================================= | 65% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 67% | |=============================================== | 68% | |================================================ | 68% | |================================================ | 69% | |================================================= | 69% | |================================================= | 70% | |================================================= | 71% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 72% | |=================================================== | 73% | |==================================================== | 74% | |==================================================== | 75% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 76% | |====================================================== | 77% | |====================================================== | 78% | |======================================================= | 78% | |======================================================= | 79% | |======================================================== | 79% | |======================================================== | 80% | |======================================================== | 81% | |========================================================= | 81% | |========================================================= | 82% | |========================================================== | 83% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 86% | |============================================================= | 87% | |============================================================= | 88% | |============================================================== | 88% | |============================================================== | 89% | |=============================================================== | 90% | |=============================================================== | 91% | |================================================================ | 91% | |================================================================ | 92% | |================================================================= | 92% | |================================================================= | 93% | |================================================================= | 94% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |===================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 99% | |======================================================================| 100% + +``` r +## preview +mapview(countyIncome, zcol = "B19019_001E") +``` + +
+ + +Notice how we needed to specify `_001E` for `zcol`. That references the +specific variable we want to map - variable 1 in the table’s estimate +(or `E`). The `M` values refer to the margin of the error - we expect +this estimate to be off by some amount within +/- this value. + +We can also download a specific column, like the median income for +one-person households (`B19019_002`): + +``` r +## download +countyIncome <- get_acs(geography = "county", year = 2019, state = 29, + variables = "B19019_002", output = "wide", + geometry = TRUE) +``` + + ## Getting data from the 2015-2019 5-year ACS + + ## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`. + +``` r +## preview +mapview(countyIncome, zcol = "B19019_002E") +``` + +
+ + +## Combining Data Sources + +Perhaps we have a range of data that we want to include. For this +example, we’ll download data on median income and the proportion of +women in tracts in Boone County, Missouri. We’ll download the income +data with `geometry = TRUE` and the sex data with `geometry = FALSE`: + +``` r +## download +booneIncome <- get_acs(geography = "tract", year = 2019, state = 29, + county = "019", variables = "B19019_001", + output = "wide", geometry = TRUE) %>% + rename(median_income = B19019_001E) %>% + select(GEOID, median_income) +``` + + ## Getting data from the 2015-2019 5-year ACS + + ## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`. + + ## | | | 0% | |======= | 9% | |============ | 17% | |=============== | 21% | |================ | 23% | |================== | 25% | |==================== | 29% | |====================== | 32% | |======================== | 35% | |========================= | 36% | |========================== | 37% | |============================== | 43% | |=================================== | 49% | |==================================== | 52% | |====================================== | 55% | |========================================== | 60% | |============================================ | 63% | |============================================== | 65% | |================================================== | 71% | |================================================== | 72% | |==================================================== | 75% | |========================================================== | 83% | |============================================================= | 87% | |================================================================= | 93% | |=================================================================== | 95% | |===================================================================== | 98% | |======================================================================| 100% + +``` r +## download +booneSex <- get_acs(geography = "tract", year = 2019, state = 29, + county = "019", variables = c("B01001_001", "B01001_026"), + output = "wide") %>% + mutate(pct_women = B01001_026E/B01001_001E*100) %>% + select(GEOID, pct_women) +``` + + ## Getting data from the 2015-2019 5-year ACS + +To combine these data, we’ll use `left_join()` from `dplyr`. Our `sf` +object should always be the first object in the join (the `x` data) and +our non-sf data should be the second data (the `y` data): + +``` r +boone <- left_join(booneIncome, booneSex, by = "GEOID") +``` + +Three common issues arise: + +1. The ID columns are named differently: `by = c("GEOID" = "geoid")` +2. The ID columns are different type: + `booneIncome <- mutate(GEOID = as.numeric(GEOID))` +3. Both objects are `sf` objects: `st_geometry(booneSEX) <- NULL` + +## Using Tigris + +To get data from the TIGER/line database, we can use the `tigris` +package. You can see a full list of the data available +[here](https://cran.r-project.org/web/packages/tigris/tigris.pdf). + +### State Data + +We can download a generalized version, which smooths out state +boundaries so that the overall image is both smaller in disk size and +(sometimes) easier to read. This is particularly helpful if you are +making small scale maps of the entire United States. We’ll get these +data at the “20m” resolution using the `states()` function: + +``` r +states <- states(cb = TRUE, resolution = "20m") +``` + + ## | | | 0% | |============ | 17% | |===================================== | 52% | |================================================= | 70% | |============================================================= | 87% | |======================================================================| 100% + +### County Data + +Now, we’ll get more detailed data - all of the county boundaries for +Missouri. We’ll use the `counties()` function using a slightly less +generalized resolution, “5m”: + +``` r +moCounties <- counties(cb = TRUE, resolution = "5m") +``` + + ## | | | 0% | |== | 2% | |=== | 4% | |=== | 5% | |==== | 6% | |===== | 8% | |======== | 12% | |========= | 12% | |========= | 13% | |========== | 15% | |=========== | 16% | |============ | 18% | |============== | 19% | |============== | 21% | |================ | 22% | |================= | 24% | |================= | 25% | |================== | 26% | |=================== | 28% | |==================== | 29% | |===================== | 30% | |====================== | 31% | |======================== | 35% | |========================= | 36% | |=========================== | 39% | |============================ | 40% | |============================= | 41% | |============================= | 42% | |============================== | 42% | |============================== | 43% | |=============================== | 45% | |================================= | 47% | |================================== | 48% | |================================== | 49% | |=================================== | 50% | |===================================== | 52% | |===================================== | 53% | |====================================== | 54% | |======================================== | 57% | |========================================= | 59% | |========================================== | 60% | |=========================================== | 62% | |============================================ | 63% | |=============================================== | 67% | |================================================ | 69% | |================================================= | 70% | |================================================== | 71% | |=================================================== | 72% | |=================================================== | 73% | |==================================================== | 74% | |==================================================== | 75% | |===================================================== | 76% | |====================================================== | 76% | |====================================================== | 77% | |======================================================= | 79% | |======================================================== | 80% | |========================================================= | 81% | |========================================================== | 83% | |=========================================================== | 84% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 87% | |============================================================== | 89% | |=============================================================== | 90% | |================================================================ | 92% | |================================================================= | 93% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 97% | |===================================================================== | 98% | |======================================================================| 100% + +### Tract Data + +Now, we’ll get even more detailed data - all of the tract boundaries for +St. Charles County, Missouri. We’ll use the `tracts()` function with +`cb = FALSE` by default: + +``` r +stCharlesTracts <- tracts(state = 29, county = 183) +``` + + ## | | | 0% | | | 1% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 9% | |======= | 10% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 16% | |============ | 17% | |============ | 18% | |============= | 18% | |============= | 19% | |============== | 19% | |============== | 20% | |============== | 21% | |=============== | 21% | |=============== | 22% | |================ | 23% | |================ | 24% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |=================== | 27% | |=================== | 28% | |==================== | 28% | |==================== | 29% | |===================== | 29% | |===================== | 30% | |===================== | 31% | |====================== | 32% | |======================= | 32% | |======================= | 33% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 37% | |========================== | 38% | |=========================== | 38% | |=========================== | 39% | |============================ | 39% | |============================ | 40% | |============================= | 41% | |============================= | 42% | |============================== | 42% | |============================== | 43% | |=============================== | 44% | |=============================== | 45% | |================================ | 45% | |================================ | 46% | |================================= | 47% | |================================= | 48% | |================================== | 49% | |=================================== | 49% | |=================================== | 50% | |=================================== | 51% | |==================================== | 51% | |==================================== | 52% | |===================================== | 52% | |===================================== | 53% | |====================================== | 54% | |====================================== | 55% | |======================================= | 55% | |======================================= | 56% | |======================================== | 56% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 60% | |============================================ | 63% | |============================================= | 64% | |============================================= | 65% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 67% | |=============================================== | 68% | |================================================ | 68% | |================================================ | 69% | |================================================= | 69% | |================================================= | 70% | |================================================= | 71% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 72% | |=================================================== | 73% | |=================================================== | 74% | |==================================================== | 74% | |==================================================== | 75% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 77% | |====================================================== | 78% | |======================================================= | 78% | |======================================================= | 79% | |======================================================== | 79% | |======================================================== | 80% | |======================================================== | 81% | |========================================================= | 82% | |========================================================== | 82% | |========================================================== | 83% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 86% | |============================================================= | 87% | |============================================================= | 88% | |============================================================== | 88% | |============================================================== | 89% | |=============================================================== | 90% | |================================================================ | 91% | |================================================================ | 92% | |================================================================= | 92% | |================================================================= | 93% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |===================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 99% | |======================================================================| 100% diff --git a/examples/meeting-2-2-examples-complete.nb.html b/examples/meeting-2-2-examples-complete.nb.html new file mode 100644 index 0000000..130fb1d --- /dev/null +++ b/examples/meeting-2-2-examples-complete.nb.html @@ -0,0 +1,1168 @@ + + + + + + + + + + + + + + +Meeting Examples - Complete + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
knitr::opts_chunk$set(cache = FALSE)
+ + + +
+

Introduction

+

This notebook illustrates data access through both tigris and tidycensus as well as joins using dplyr.

+
+
+

Dependencies

+

This notebook requires the following packages:

+ + + +
# tidyverse packages
+library(dplyr)       # data wrangling
+ + +

+Attaching package: ‘dplyr’
+
+The following objects are masked from ‘package:stats’:
+
+    filter, lag
+
+The following objects are masked from ‘package:base’:
+
+    intersect, setdiff, setequal, union
+ + +
# spatial packages
+library(mapview)     # preview geometric data
+ + +
Registered S3 method overwritten by 'htmlwidgets':
+  method           from         
+  print.htmlwidget tools:rstudio
+ + +
library(sf)          # spatial tools
+ + +
Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1
+ + +
library(tidycensus)  # demographic data
+library(tigris)      # tiger/line data
+ + +
To enable 
+caching of data, set `options(tigris_use_cache = TRUE)` in your R script or .Rprofile.
+
+Attaching package: ‘tigris’
+
+The following object is masked from ‘package:tidycensus’:
+
+    fips_codes
+ + +
# other packages
+library(here)        # file path management
+ + +
here() starts at /Users/prenercg/GitHub/slu-soc5650/module-2-combine-sources
+ + + +
+
+

tidycensus Set-up

+

Before using tidycensus, you need to install a census API key. Use the syntax below, copied into your console, to install the key you received via email.

+
census_api_key("KEY", install = TRUE)
+

This is not a code chunk you will need in each notebook. As long as install = TRUE, you will only have to do this once!

+
+
+

Decennial Census Data

+
+

Get List of Variables

+

To get a preview of variables available in the get_decennial() function, we can use the load_variables() function:

+ + + +
census <- load_variables(year = 2000, dataset = "sf1") 
+ + + +

I find it useful to assign the output of this function to an object so that I can search through it. Try searching for the variable P0010001, the total population of a geographic unit, in the census object.

+
+
+

Download a Single Variable

+

To download data, we can use use the get_decennial() function to access, for example, population by state in 2000:

+ + + +
popStates <- get_decennial(geography = "state", year = 2000, variable = "P001001")
+ + + +

A full list of the geographies available in tidycensus can be found here.

+
+
+

Download a Full Table

+

Most variables in the decennial census are actually a part of a table. There are individual variables, for example, for race:

+ + + +
census %>%
+  filter(concept == "P3. RACE [8]")
+ + +
+ +
+ + + +

We rarely want to download these one at a time. Instead, we want to download them at one time into a single data frame. The table number for these data is P003 - we take the first four characters from the name variable.

+ + + +
cityRace00 <- get_decennial(geography = "tract", year = 2000, state = 29,
+                            county = "510", table = "P003", output = "wide")
+ + + +

We’ve used the FIPS codes for both Missouri (29) and St. Louis City (29510) here - you can find a full list of Missouri counties here.

+
+
+

Add Geometry

+

The tidycensus package also includes tools for downloading the geometries for these data as well. For instance, we can add geometric data to our previous call for City of St. Louis tract-level data on race by adding the geometry = TRUE argument:

+ + + +
## download
+cityRace00 <- get_decennial(geography = "tract", year = 2000, state = 29,
+                            county = "510", table = "P003", output = "wide",
+                            geometry = TRUE)
+ + +
Getting data from the 2000 decennial Census
+Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
+Loading SF1 variables for 2000 from table P003. To cache this dataset for faster access to Census tables in the future, run this function with `cache_table = TRUE`. You only need to do this once per Census dataset.
+Using Census Summary File 1
+Using Census Summary File 1
+ + +

+  |                                                                                                                                                         
+  |                                                                                                                                                   |   0%
+  |                                                                                                                                                         
+  |==                                                                                                                                                 |   1%
+  |                                                                                                                                                         
+  |===                                                                                                                                                |   2%
+  |                                                                                                                                                         
+  |====                                                                                                                                               |   3%
+  |                                                                                                                                                         
+  |=====                                                                                                                                              |   3%
+  |                                                                                                                                                         
+  |=====                                                                                                                                              |   4%
+  |                                                                                                                                                         
+  |======                                                                                                                                             |   4%
+  |                                                                                                                                                         
+  |=======                                                                                                                                            |   5%
+  |                                                                                                                                                         
+  |========                                                                                                                                           |   5%
+  |                                                                                                                                                         
+  |=========                                                                                                                                          |   6%
+  |                                                                                                                                                         
+  |==========                                                                                                                                         |   7%
+  |                                                                                                                                                         
+  |===========                                                                                                                                        |   7%
+  |                                                                                                                                                         
+  |===========                                                                                                                                        |   8%
+  |                                                                                                                                                         
+  |============                                                                                                                                       |   8%
+  |                                                                                                                                                         
+  |=============                                                                                                                                      |   9%
+  |                                                                                                                                                         
+  |==============                                                                                                                                     |   9%
+  |                                                                                                                                                         
+  |==============                                                                                                                                     |  10%
+  |                                                                                                                                                         
+  |===============                                                                                                                                    |  10%
+  |                                                                                                                                                         
+  |================                                                                                                                                   |  11%
+  |                                                                                                                                                         
+  |=================                                                                                                                                  |  11%
+  |                                                                                                                                                         
+  |=================                                                                                                                                  |  12%
+  |                                                                                                                                                         
+  |==================                                                                                                                                 |  12%
+  |                                                                                                                                                         
+  |==================                                                                                                                                 |  13%
+  |                                                                                                                                                         
+  |===================                                                                                                                                |  13%
+  |                                                                                                                                                         
+  |====================                                                                                                                               |  13%
+  |                                                                                                                                                         
+  |====================                                                                                                                               |  14%
+  |                                                                                                                                                         
+  |======================                                                                                                                             |  15%
+  |                                                                                                                                                         
+  |=======================                                                                                                                            |  16%
+  |                                                                                                                                                         
+  |========================                                                                                                                           |  16%
+  |                                                                                                                                                         
+  |==========================                                                                                                                         |  17%
+  |                                                                                                                                                         
+  |===========================                                                                                                                        |  19%
+  |                                                                                                                                                         
+  |=============================                                                                                                                      |  20%
+  |                                                                                                                                                         
+  |===============================                                                                                                                    |  21%
+  |                                                                                                                                                         
+  |=================================                                                                                                                  |  22%
+  |                                                                                                                                                         
+  |==================================                                                                                                                 |  23%
+  |                                                                                                                                                         
+  |====================================                                                                                                               |  25%
+  |                                                                                                                                                         
+  |======================================                                                                                                             |  26%
+  |                                                                                                                                                         
+  |========================================                                                                                                           |  27%
+  |                                                                                                                                                         
+  |==========================================                                                                                                         |  28%
+  |                                                                                                                                                         
+  |============================================                                                                                                       |  30%
+  |                                                                                                                                                         
+  |==============================================                                                                                                     |  31%
+  |                                                                                                                                                         
+  |===============================================                                                                                                    |  32%
+  |                                                                                                                                                         
+  |================================================                                                                                                   |  32%
+  |                                                                                                                                                         
+  |=================================================                                                                                                  |  33%
+  |                                                                                                                                                         
+  |===================================================                                                                                                |  35%
+  |                                                                                                                                                         
+  |====================================================                                                                                               |  36%
+  |                                                                                                                                                         
+  |=======================================================                                                                                            |  37%
+  |                                                                                                                                                         
+  |========================================================                                                                                           |  38%
+  |                                                                                                                                                         
+  |==========================================================                                                                                         |  40%
+  |                                                                                                                                                         
+  |============================================================                                                                                       |  41%
+  |                                                                                                                                                         
+  |===============================================================                                                                                    |  43%
+  |                                                                                                                                                         
+  |===================================================================                                                                                |  45%
+  |                                                                                                                                                         
+  |=====================================================================                                                                              |  47%
+  |                                                                                                                                                         
+  |======================================================================                                                                             |  48%
+  |                                                                                                                                                         
+  |=========================================================================                                                                          |  49%
+  |                                                                                                                                                         
+  |==========================================================================                                                                         |  50%
+  |                                                                                                                                                         
+  |==============================================================================                                                                     |  53%
+  |                                                                                                                                                         
+  |=================================================================================                                                                  |  55%
+  |                                                                                                                                                         
+  |====================================================================================                                                               |  57%
+  |                                                                                                                                                         
+  |=====================================================================================                                                              |  58%
+  |                                                                                                                                                         
+  |=======================================================================================                                                            |  59%
+  |                                                                                                                                                         
+  |===========================================================================================                                                        |  62%
+  |                                                                                                                                                         
+  |============================================================================================                                                       |  63%
+  |                                                                                                                                                         
+  |================================================================================================                                                   |  65%
+  |                                                                                                                                                         
+  |==================================================================================================                                                 |  67%
+  |                                                                                                                                                         
+  |===================================================================================================                                                |  67%
+  |                                                                                                                                                         
+  |=======================================================================================================                                            |  70%
+  |                                                                                                                                                         
+  |==========================================================================================================                                         |  72%
+  |                                                                                                                                                         
+  |==============================================================================================================                                     |  75%
+  |                                                                                                                                                         
+  |=================================================================================================================                                  |  77%
+  |                                                                                                                                                         
+  |====================================================================================================================                               |  79%
+  |                                                                                                                                                         
+  |=====================================================================================================================                              |  80%
+  |                                                                                                                                                         
+  |=======================================================================================================================                            |  81%
+  |                                                                                                                                                         
+  |=========================================================================================================================                          |  82%
+  |                                                                                                                                                         
+  |===========================================================================================================================                        |  84%
+  |                                                                                                                                                         
+  |============================================================================================================================                       |  84%
+  |                                                                                                                                                         
+  |================================================================================================================================                   |  87%
+  |                                                                                                                                                         
+  |==================================================================================================================================                 |  89%
+  |                                                                                                                                                         
+  |=====================================================================================================================================              |  90%
+  |                                                                                                                                                         
+  |=========================================================================================================================================          |  93%
+  |                                                                                                                                                         
+  |==============================================================================================================================================     |  97%
+  |                                                                                                                                                         
+  |===================================================================================================================================================| 100%
+ + +
## preview
+mapview(cityRace00, zcol = "P003005")
+ + + + + +
+ + + + + + + + +

Notice how I used the zcol argument for mapview() to preview a specific set of data as a thematic layer on the map! These data are not normalized, but we do get a quick preview of the distribution of Asian residents in St. Louis City.

+
+
+
+

Decennial Census Data

+
+

Get List of Variables

+

To get a preview of variables available in the get_acs() function, we can use the load_variables() function again. We’ll use "acs5" for our dataset and, for this example, we’ll pull from the most recent 2019 ACS year:

+ + + +
census <- load_variables(year = 2019, dataset = "acs5") 
+ + + +

Try searching for the table B19013, the median household income table.

+
+
+

Get and Interpret ACS Data

+

We’ll illustrate get_acs() by using the data in table B19019. First, we’ll download these data as a full table for all counties in Missouri:

+ + + +
## download
+countyIncome <- get_acs(geography = "county", year = 2019, state = 29,
+                        table = "B19019", output = "wide", geometry = TRUE)
+ + +
Getting data from the 2015-2019 5-year ACS
+Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
+Loading ACS5 variables for 2019 from table B19019. To cache this dataset for faster access to ACS tables in the future, run this function with `cache_table = TRUE`. You only need to do this once per ACS dataset.
+ + +

+  |                                                                                                                                                         
+  |                                                                                                                                                   |   0%
+  |                                                                                                                                                         
+  |=                                                                                                                                                  |   1%
+  |                                                                                                                                                         
+  |===                                                                                                                                                |   2%
+  |                                                                                                                                                         
+  |====                                                                                                                                               |   2%
+  |                                                                                                                                                         
+  |=====                                                                                                                                              |   3%
+  |                                                                                                                                                         
+  |======                                                                                                                                             |   4%
+  |                                                                                                                                                         
+  |=======                                                                                                                                            |   5%
+  |                                                                                                                                                         
+  |=========                                                                                                                                          |   6%
+  |                                                                                                                                                         
+  |==========                                                                                                                                         |   7%
+  |                                                                                                                                                         
+  |===========                                                                                                                                        |   7%
+  |                                                                                                                                                         
+  |============                                                                                                                                       |   8%
+  |                                                                                                                                                         
+  |=============                                                                                                                                      |   9%
+  |                                                                                                                                                         
+  |==============                                                                                                                                     |   9%
+  |                                                                                                                                                         
+  |==============                                                                                                                                     |  10%
+  |                                                                                                                                                         
+  |===============                                                                                                                                    |  10%
+  |                                                                                                                                                         
+  |===============                                                                                                                                    |  11%
+  |                                                                                                                                                         
+  |=================                                                                                                                                  |  12%
+  |                                                                                                                                                         
+  |==================                                                                                                                                 |  12%
+  |                                                                                                                                                         
+  |===================                                                                                                                                |  13%
+  |                                                                                                                                                         
+  |====================                                                                                                                               |  13%
+  |                                                                                                                                                         
+  |====================                                                                                                                               |  14%
+  |                                                                                                                                                         
+  |======================                                                                                                                             |  15%
+  |                                                                                                                                                         
+  |=======================                                                                                                                            |  16%
+  |                                                                                                                                                         
+  |========================                                                                                                                           |  16%
+  |                                                                                                                                                         
+  |=========================                                                                                                                          |  17%
+  |                                                                                                                                                         
+  |==========================                                                                                                                         |  18%
+  |                                                                                                                                                         
+  |===========================                                                                                                                        |  18%
+  |                                                                                                                                                         
+  |============================                                                                                                                       |  19%
+  |                                                                                                                                                         
+  |=============================                                                                                                                      |  20%
+  |                                                                                                                                                         
+  |==============================                                                                                                                     |  20%
+  |                                                                                                                                                         
+  |===============================                                                                                                                    |  21%
+  |                                                                                                                                                         
+  |=================================                                                                                                                  |  23%
+  |                                                                                                                                                         
+  |==================================                                                                                                                 |  23%
+  |                                                                                                                                                         
+  |====================================                                                                                                               |  25%
+  |                                                                                                                                                         
+  |=====================================                                                                                                              |  25%
+  |                                                                                                                                                         
+  |======================================                                                                                                             |  26%
+  |                                                                                                                                                         
+  |=======================================                                                                                                            |  26%
+  |                                                                                                                                                         
+  |=========================================                                                                                                          |  28%
+  |                                                                                                                                                         
+  |===========================================                                                                                                        |  29%
+  |                                                                                                                                                         
+  |==============================================                                                                                                     |  31%
+  |                                                                                                                                                         
+  |=================================================                                                                                                  |  33%
+  |                                                                                                                                                         
+  |===================================================                                                                                                |  35%
+  |                                                                                                                                                         
+  |====================================================                                                                                               |  35%
+  |                                                                                                                                                         
+  |=====================================================                                                                                              |  36%
+  |                                                                                                                                                         
+  |=======================================================                                                                                            |  38%
+  |                                                                                                                                                         
+  |=========================================================                                                                                          |  39%
+  |                                                                                                                                                         
+  |============================================================                                                                                       |  41%
+  |                                                                                                                                                         
+  |=============================================================                                                                                      |  42%
+  |                                                                                                                                                         
+  |===============================================================                                                                                    |  43%
+  |                                                                                                                                                         
+  |===================================================================                                                                                |  45%
+  |                                                                                                                                                         
+  |=====================================================================                                                                              |  47%
+  |                                                                                                                                                         
+  |=======================================================================                                                                            |  48%
+  |                                                                                                                                                         
+  |=========================================================================                                                                          |  49%
+  |                                                                                                                                                         
+  |==========================================================================                                                                         |  51%
+  |                                                                                                                                                         
+  |===========================================================================                                                                        |  51%
+  |                                                                                                                                                         
+  |=============================================================================                                                                      |  52%
+  |                                                                                                                                                         
+  |==============================================================================                                                                     |  53%
+  |                                                                                                                                                         
+  |===============================================================================                                                                    |  53%
+  |                                                                                                                                                         
+  |===============================================================================                                                                    |  54%
+  |                                                                                                                                                         
+  |================================================================================                                                                   |  54%
+  |                                                                                                                                                         
+  |=================================================================================                                                                  |  55%
+  |                                                                                                                                                         
+  |===================================================================================                                                                |  56%
+  |                                                                                                                                                         
+  |====================================================================================                                                               |  57%
+  |                                                                                                                                                         
+  |======================================================================================                                                             |  59%
+  |                                                                                                                                                         
+  |=======================================================================================                                                            |  59%
+  |                                                                                                                                                         
+  |=========================================================================================                                                          |  61%
+  |                                                                                                                                                         
+  |==========================================================================================                                                         |  61%
+  |                                                                                                                                                         
+  |===========================================================================================                                                        |  62%
+  |                                                                                                                                                         
+  |============================================================================================                                                       |  62%
+  |                                                                                                                                                         
+  |============================================================================================                                                       |  63%
+  |                                                                                                                                                         
+  |=============================================================================================                                                      |  63%
+  |                                                                                                                                                         
+  |===============================================================================================                                                    |  65%
+  |                                                                                                                                                         
+  |=================================================================================================                                                  |  66%
+  |                                                                                                                                                         
+  |===================================================================================================                                                |  68%
+  |                                                                                                                                                         
+  |=====================================================================================================                                              |  69%
+  |                                                                                                                                                         
+  |=======================================================================================================                                            |  70%
+  |                                                                                                                                                         
+  |=========================================================================================================                                          |  71%
+  |                                                                                                                                                         
+  |===========================================================================================================                                        |  73%
+  |                                                                                                                                                         
+  |=============================================================================================================                                      |  74%
+  |                                                                                                                                                         
+  |==============================================================================================================                                     |  75%
+  |                                                                                                                                                         
+  |=================================================================================================================                                  |  77%
+  |                                                                                                                                                         
+  |====================================================================================================================                               |  79%
+  |                                                                                                                                                         
+  |======================================================================================================================                             |  81%
+  |                                                                                                                                                         
+  |========================================================================================================================                           |  81%
+  |                                                                                                                                                         
+  |===========================================================================================================================                        |  84%
+  |                                                                                                                                                         
+  |=============================================================================================================================                      |  85%
+  |                                                                                                                                                         
+  |===============================================================================================================================                    |  87%
+  |                                                                                                                                                         
+  |=================================================================================================================================                  |  88%
+  |                                                                                                                                                         
+  |===================================================================================================================================                |  89%
+  |                                                                                                                                                         
+  |=====================================================================================================================================              |  90%
+  |                                                                                                                                                         
+  |=======================================================================================================================================            |  92%
+  |                                                                                                                                                         
+  |==========================================================================================================================================         |  94%
+  |                                                                                                                                                         
+  |=============================================================================================================================================      |  96%
+  |                                                                                                                                                         
+  |================================================================================================================================================   |  98%
+  |                                                                                                                                                         
+  |================================================================================================================================================== |  99%
+  |                                                                                                                                                         
+  |===================================================================================================================================================| 100%
+ + +
## preview
+mapview(countyIncome, zcol = "B19019_001E")
+ + + + + +
+ + + + + + + + +

Notice how we needed to specify _001E for zcol. That references the specific variable we want to map - variable 1 in the table’s estimate (or E). The M values refer to the margin of the error - we expect this estimate to be off by some amount within +/- this value.

+

We can also download a specific column, like the median income for one-person households (B19019_002):

+ + + +
## download
+countyIncome <- get_acs(geography = "county", year = 2019, state = 29,
+                        variables = "B19019_002", output = "wide", 
+                        geometry = TRUE)
+ + +
Getting data from the 2015-2019 5-year ACS
+Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
+ + +
## preview
+mapview(countyIncome, zcol = "B19019_002E")
+ + + + + +
+ + + + + + + + +
+
+
+

Combining Data Sources

+

Perhaps we have a range of data that we want to include. For this example, we’ll download data on median income and the proportion of women in tracts in Boone County, Missouri. We’ll download the income data with geometry = TRUE and the sex data with geometry = FALSE:

+ + + +
## download
+booneIncome <- get_acs(geography = "tract", year = 2019, state = 29,
+                       county = "019", variables = "B19019_001", 
+                       output = "wide", geometry = TRUE) %>%
+  rename(median_income = B19019_001E) %>%
+  select(GEOID, median_income)
+ + +
Getting data from the 2015-2019 5-year ACS
+Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
+ + +

+  |                                                                                                                                                         
+  |                                                                                                                                                   |   0%
+  |                                                                                                                                                         
+  |========================                                                                                                                           |  17%
+  |                                                                                                                                                         
+  |===================================================================================================================================================| 100%
+ + +
## download
+booneSex <- get_acs(geography = "tract", year = 2019, state = 29,
+                       county = "019", variables = c("B01001_001", "B01001_026"),
+                       output = "wide") %>%
+  mutate(pct_women = B01001_026E/B01001_001E*100) %>%
+  select(GEOID, pct_women)
+ + +
Getting data from the 2015-2019 5-year ACS
+ + + +

To combine these data, we’ll use left_join() from dplyr. Our sf object should always be the first object in the join (the x data) and our non-sf data should be the second data (the y data):

+ + + +
boone <- left_join(booneIncome, booneSex, by = "GEOID")
+ + + +

Three common issues arise:

+
    +
  1. The ID columns are named differently: by = c("GEOID" = "geoid")
  2. +
  3. The ID columns are different type: booneIncome <- mutate(GEOID = as.numeric(GEOID))
  4. +
  5. Both objects are sf objects: st_geometry(booneSEX) <- NULL
  6. +
+
+
+

Using Tigris

+

To get data from the TIGER/line database, we can use the tigris package. You can see a full list of the data available here.

+
+

State Data

+

We can download a generalized version, which smooths out state boundaries so that the overall image is both smaller in disk size and (sometimes) easier to read. This is particularly helpful if you are making small scale maps of the entire United States. We’ll get these data at the “20m” resolution using the states() function:

+ + + +
states <- states(cb = TRUE, resolution = "20m")
+ + +

+  |                                                                                                                                                         
+  |                                                                                                                                                   |   0%
+  |                                                                                                                                                         
+  |================================================================================================================================                   |  87%
+  |                                                                                                                                                         
+  |===================================================================================================================================================| 100%
+ + + +
+
+

County Data

+

Now, we’ll get more detailed data - all of the county boundaries for Missouri. We’ll use the counties() function using a slightly less generalized resolution, “5m”:

+ + + +
moCounties <- counties(cb = TRUE, resolution = "5m")
+ + +

+  |                                                                                                                                                         
+  |                                                                                                                                                   |   0%
+  |                                                                                                                                                         
+  |==                                                                                                                                                 |   1%
+  |                                                                                                                                                         
+  |==========================                                                                                                                         |  18%
+  |                                                                                                                                                         
+  |==============================================                                                                                                     |  32%
+  |                                                                                                                                                         
+  |==============================================================                                                                                     |  42%
+  |                                                                                                                                                         
+  |========================================================================                                                                           |  49%
+  |                                                                                                                                                         
+  |===========================================================================                                                                        |  51%
+  |                                                                                                                                                         
+  |===================================================================================================                                                |  67%
+  |                                                                                                                                                         
+  |====================================================================================================                                               |  68%
+  |                                                                                                                                                         
+  |===================================================================================================================================================| 100%
+ + + +
+
+

Tract Data

+

Now, we’ll get even more detailed data - all of the tract boundaries for St. Charles County, Missouri. We’ll use the tracts() function with cb = FALSE by default:

+ + + +
stCharlesTracts <- tracts(state = 29, county = 183)
+ + +

+  |                                                                                                                                                         
+  |                                                                                                                                                   |   0%
+  |                                                                                                                                                         
+  |=                                                                                                                                                  |   1%
+  |                                                                                                                                                         
+  |==========                                                                                                                                         |   7%
+  |                                                                                                                                                         
+  |==============                                                                                                                                     |   9%
+  |                                                                                                                                                         
+  |===============                                                                                                                                    |  10%
+  |                                                                                                                                                         
+  |================                                                                                                                                   |  11%
+  |                                                                                                                                                         
+  |=================                                                                                                                                  |  11%
+  |                                                                                                                                                         
+  |===================                                                                                                                                |  13%
+  |                                                                                                                                                         
+  |=====================                                                                                                                              |  14%
+  |                                                                                                                                                         
+  |======================                                                                                                                             |  15%
+  |                                                                                                                                                         
+  |===========================                                                                                                                        |  19%
+  |                                                                                                                                                         
+  |===============================                                                                                                                    |  21%
+  |                                                                                                                                                         
+  |=================================                                                                                                                  |  22%
+  |                                                                                                                                                         
+  |=================================                                                                                                                  |  23%
+  |                                                                                                                                                         
+  |=====================================                                                                                                              |  25%
+  |                                                                                                                                                         
+  |======================================                                                                                                             |  26%
+  |                                                                                                                                                         
+  |===========================================                                                                                                        |  29%
+  |                                                                                                                                                         
+  |===============================================                                                                                                    |  32%
+  |                                                                                                                                                         
+  |================================================                                                                                                   |  32%
+  |                                                                                                                                                         
+  |================================================                                                                                                   |  33%
+  |                                                                                                                                                         
+  |==================================================                                                                                                 |  34%
+  |                                                                                                                                                         
+  |======================================================                                                                                             |  36%
+  |                                                                                                                                                         
+  |========================================================                                                                                           |  38%
+  |                                                                                                                                                         
+  |=========================================================                                                                                          |  39%
+  |                                                                                                                                                         
+  |==============================================================                                                                                     |  42%
+  |                                                                                                                                                         
+  |===============================================================                                                                                    |  43%
+  |                                                                                                                                                         
+  |==================================================================                                                                                 |  45%
+  |                                                                                                                                                         
+  |====================================================================                                                                               |  46%
+  |                                                                                                                                                         
+  |======================================================================                                                                             |  48%
+  |                                                                                                                                                         
+  |=========================================================================                                                                          |  49%
+  |                                                                                                                                                         
+  |=============================================================================                                                                      |  52%
+  |                                                                                                                                                         
+  |=============================================================================                                                                      |  53%
+  |                                                                                                                                                         
+  |================================================================================                                                                   |  54%
+  |                                                                                                                                                         
+  |================================================================================                                                                   |  55%
+  |                                                                                                                                                         
+  |=================================================================================                                                                  |  55%
+  |                                                                                                                                                         
+  |===================================================================================                                                                |  56%
+  |                                                                                                                                                         
+  |===================================================================================                                                                |  57%
+  |                                                                                                                                                         
+  |====================================================================================                                                               |  57%
+  |                                                                                                                                                         
+  |=====================================================================================                                                              |  58%
+  |                                                                                                                                                         
+  |========================================================================================                                                           |  60%
+  |                                                                                                                                                         
+  |=========================================================================================                                                          |  60%
+  |                                                                                                                                                         
+  |=========================================================================================                                                          |  61%
+  |                                                                                                                                                         
+  |===========================================================================================                                                        |  62%
+  |                                                                                                                                                         
+  |============================================================================================                                                       |  62%
+  |                                                                                                                                                         
+  |==============================================================================================                                                     |  64%
+  |                                                                                                                                                         
+  |=================================================================================================                                                  |  66%
+  |                                                                                                                                                         
+  |===================================================================================================                                                |  68%
+  |                                                                                                                                                         
+  |======================================================================================================                                             |  70%
+  |                                                                                                                                                         
+  |=========================================================================================================                                          |  72%
+  |                                                                                                                                                         
+  |===========================================================================================================                                        |  73%
+  |                                                                                                                                                         
+  |=============================================================================================================                                      |  74%
+  |                                                                                                                                                         
+  |=================================================================================================================                                  |  77%
+  |                                                                                                                                                         
+  |====================================================================================================================                               |  79%
+  |                                                                                                                                                         
+  |=======================================================================================================================                            |  81%
+  |                                                                                                                                                         
+  |==========================================================================================================================                         |  83%
+  |                                                                                                                                                         
+  |=============================================================================================================================                      |  85%
+  |                                                                                                                                                         
+  |===============================================================================================================================                    |  86%
+  |                                                                                                                                                         
+  |================================================================================================================================                   |  87%
+  |                                                                                                                                                         
+  |===================================================================================================================================                |  89%
+  |                                                                                                                                                         
+  |=====================================================================================================================================              |  91%
+  |                                                                                                                                                         
+  |=========================================================================================================================================          |  93%
+  |                                                                                                                                                         
+  |============================================================================================================================================       |  95%
+  |                                                                                                                                                         
+  |=================================================================================================================================================  |  99%
+  |                                                                                                                                                         
+  |===================================================================================================================================================| 100%
+ + + + +
+
+ +
LS0tCnRpdGxlOiAiTWVldGluZyBFeGFtcGxlcyAtIENvbXBsZXRlIgphdXRob3I6ICJDaHJpc3RvcGhlciBQcmVuZXIsIFBoRCIKZGF0ZTogJyhgciBmb3JtYXQoU3lzLnRpbWUoKSwgIiVCICVkLCAlWSIpYCknCm91dHB1dDogCiAgZ2l0aHViX2RvY3VtZW50OiBkZWZhdWx0CiAgaHRtbF9ub3RlYm9vazogZGVmYXVsdCAKLS0tCgpgYGB7ciBzZXR1cH0Ka25pdHI6Om9wdHNfY2h1bmskc2V0KGNhY2hlID0gRkFMU0UpCmBgYAoKIyMgSW50cm9kdWN0aW9uClRoaXMgbm90ZWJvb2sgaWxsdXN0cmF0ZXMgZGF0YSBhY2Nlc3MgdGhyb3VnaCBib3RoIGB0aWdyaXNgIGFuZCBgdGlkeWNlbnN1c2AgYXMgd2VsbCBhcyBqb2lucyB1c2luZyBg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W5kYXJpZXMgZm9yIFN0LiBDaGFybGVzIENvdW50eSwgTWlzc291cmkuIFdlJ2xsIHVzZSB0aGUgYHRyYWN0cygpYCBmdW5jdGlvbiB3aXRoIGBjYiA9IEZBTFNFYCBieSBkZWZhdWx0OgoKYGBge3IgZ2V0LXRyYWN0c30Kc3RDaGFybGVzVHJhY3RzIDwtIHRyYWN0cyhzdGF0ZSA9IDI5LCBjb3VudHkgPSAxODMpCmBgYAoKYGBge3IgbW92ZS10by1kb2NzLCBpbmNsdWRlPUZBTFNFfQojIHlvdSBkbyBuZWVkIHRvIGluY2x1ZGUgdGhpcyBpbiBhbnkgbm90ZWJvb2sgeW91IGNyZWF0ZSBmb3IgdGhpcyBjbGFzcwpmczo6ZmlsZV9jb3B5KGhlcmU6OmhlcmUoImV4YW1wbGVzIiwgIm1lZXRpbmctMi0yLWV4YW1wbGVzLWNvbXBsZXRlLm5iLmh0bWwiKSwgCiAgICAgICAgICAgICAgaGVyZTo6aGVyZSgiZG9jcyIsICJpbmRleC5uYi5odG1sIiksIAogICAgICAgICAgICAgIG92ZXJ3cml0ZSA9IFRSVUUpCmBgYA==
+ + + +
+ + + + + + + + + + + + + + + + diff --git a/examples/module-examples.Rmd b/examples/meeting-2-2-examples.Rmd similarity index 100% rename from examples/module-examples.Rmd rename to examples/meeting-2-2-examples.Rmd diff --git a/examples/module-examples-complete.md b/examples/module-examples-complete.md deleted file mode 100644 index 57f95e5..0000000 --- a/examples/module-examples-complete.md +++ /dev/null @@ -1,335 +0,0 @@ -Meeting Examples - Complete -================ -Christopher Prener, PhD -(March 01, 2021) - -``` r -knitr::opts_chunk$set(cache = FALSE) -``` - -## Introduction - -This notebook illustrates data access through both `tigris` and -`tidycensus` as well as joins using `dplyr`. - -## Dependencies - -This notebook requires the following packages: - -``` r -# tidyverse packages -library(dplyr) # data wrangling -``` - - ## - ## Attaching package: 'dplyr' - - ## The following objects are masked from 'package:stats': - ## - ## filter, lag - - ## The following objects are masked from 'package:base': - ## - ## intersect, setdiff, setequal, union - -``` r -# spatial packages -library(mapview) # preview geometric data -``` - - ## GDAL version >= 3.1.0 | setting mapviewOptions(fgb = TRUE) - -``` r -library(sf) # spatial tools -``` - - ## Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1 - -``` r -library(tidycensus) # demographic data -library(tigris) # tiger/line data -``` - - ## To enable - ## caching of data, set `options(tigris_use_cache = TRUE)` in your R script or .Rprofile. - -``` r -# other packages -library(here) # file path management -``` - - ## here() starts at /Users/chris/GitHub/slu-soc5650/content/module-2-combine-sources - -## tidycensus Set-up - -Before using `tidycensus`, you need to install a census API key. Use the -syntax below, copied into your console, to install the key you received -via email. - -``` r -census_api_key("KEY", install = TRUE) -``` - -This is not a code chunk you will need in each notebook. As long as -`install = TRUE`, you will only have to do this once! - -## Decennial Census Data - -### Get List of Variables - -To get a preview of variables available in the `get_decennial()` -function, we can use the `load_variables()` function: - -``` r -census <- load_variables(year = 2000, dataset = "sf1") -``` - -I find it useful to assign the output of this function to an object so -that I can search through it. Try searching for the variable `P0010001`, -the total population of a geographic unit, in the `census` object. - -### Download a Single Variable - -To download data, we can use use the `get_decennial()` function to -access, for example, population by state in 2000: - -``` r -popStates <- get_decennial(geography = "state", year = 2000, variable = "P001001") -``` - - ## Getting data from the 2000 decennial Census - - ## Using Census Summary File 1 - -A full list of the geographies available in `tidycensus` can be found -[here](https://walker-data.com/tidycensus/articles/basic-usage.html#geography-in-tidycensus-1). - -### Download a Full Table - -Most variables in the decennial census are actually a part of a table. -There are individual variables, for example, for race: - -``` r -census %>% - filter(concept == "P3. RACE [8]") -``` - - ## # A tibble: 0 x 3 - ## # … with 3 variables: name , label , concept - -We rarely want to download these one at a time. Instead, we want to -download them at one time into a single data frame. The table number for -these data is `P003` - we take the first four characters from the `name` -variable. - -``` r -cityRace00 <- get_decennial(geography = "tract", year = 2000, state = 29, - county = "510", table = "P003", output = "wide") -``` - - ## Getting data from the 2000 decennial Census - - ## Loading SF1 variables for 2000 from table P003. To cache this dataset for faster access to Census tables in the future, run this function with `cache_table = TRUE`. You only need to do this once per Census dataset. - - ## Using Census Summary File 1 - ## Using Census Summary File 1 - -We’ve used the FIPS codes for both Missouri (`29`) and St. Louis City -(`29510`) here - you can find a full list of Missouri counties -[here](https://www.msdis.missouri.edu/resources/fips.html). - -### Add Geometry - -The `tidycensus` package also includes tools for downloading the -geometries for these data as well. For instance, we can add geometric -data to our previous call for City of St. Louis tract-level data on race -by adding the `geometry = TRUE` argument: - -``` r -## download -cityRace00 <- get_decennial(geography = "tract", year = 2000, state = 29, - county = "510", table = "P003", output = "wide", - geometry = TRUE) -``` - - ## Getting data from the 2000 decennial Census - - ## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`. - - ## Loading SF1 variables for 2000 from table P003. To cache this dataset for faster access to Census tables in the future, run this function with `cache_table = TRUE`. You only need to do this once per Census dataset. - - ## Using Census Summary File 1 - ## Using Census Summary File 1 - - ## | | | 0% | | | 1% | |= | 1% | |= | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 10% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========== | 14% | |========== | 15% | |=========== | 16% | |============ | 17% | |============ | 18% | |============= | 19% | |============== | 20% | |=============== | 21% | |================ | 22% | |================ | 23% | |================= | 24% | |================== | 26% | |=================== | 27% | |=================== | 28% | |==================== | 29% | |===================== | 30% | |===================== | 31% | |====================== | 32% | |======================= | 33% | |======================== | 34% | |========================= | 35% | |========================== | 37% | |=========================== | 39% | |============================ | 40% | |============================= | 42% | |============================== | 43% | |================================ | 45% | |================================= | 47% | |================================== | 48% | |=================================== | 50% | |==================================== | 52% | |===================================== | 53% | |====================================== | 55% | |======================================= | 56% | |======================================== | 57% | |========================================= | 58% | |========================================== | 60% | |=========================================== | 61% | |=========================================== | 62% | |============================================= | 64% | |============================================== | 65% | |=============================================== | 67% | |================================================ | 68% | |================================================= | 70% | |================================================== | 72% | |=================================================== | 73% | |==================================================== | 75% | |====================================================== | 77% | |======================================================= | 78% | |======================================================== | 80% | |========================================================= | 81% | |========================================================== | 83% | |=========================================================== | 85% | |============================================================= | 87% | |============================================================== | 88% | |=============================================================== | 89% | |================================================================ | 91% | |================================================================= | 93% | |================================================================== | 94% | |=================================================================== | 96% | |==================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 100% - -``` r -## preview -mapview(cityRace00, zcol = "P003005") -``` - -![](module-examples-complete_files/figure-gfm/unnamed-chunk-1-1.png) - -Notice how I used the `zcol` argument for `mapview()` to preview a -specific set of data as a thematic layer on the map! These data are not -normalized, but we do get a quick preview of the distribution of Asian -residents in St. Louis City. - -## Decennial Census Data - -### Get List of Variables - -To get a preview of variables available in the `get_acs()` function, we -can use the `load_variables()` function again. We’ll use `"acs5"` for -our dataset and, for this example, we’ll pull from the most recent 2019 -ACS year: - -``` r -census <- load_variables(year = 2019, dataset = "acs5") -``` - -Try searching for the table `B19013`, the median household income table. - -### Get and Interpret ACS Data - -We’ll illustrate `get_acs()` by using the data in table `B19019`. First, -we’ll download these data as a full table for all counties in Missouri: - -``` r -## download -countyIncome <- get_acs(geography = "county", year = 2019, state = 29, - table = "B19019", output = "wide", geometry = TRUE) -``` - - ## Getting data from the 2015-2019 5-year ACS - - ## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`. - - ## Loading ACS5 variables for 2019 from table B19019. To cache this dataset for faster access to ACS tables in the future, run this function with `cache_table = TRUE`. You only need to do this once per ACS dataset. - - ## | | | 0% | | | 1% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 9% | |======= | 10% | |======= | 11% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 17% | |============ | 18% | |============= | 18% | |============= | 19% | |============== | 19% | |============== | 20% | |============== | 21% | |=============== | 21% | |=============== | 22% | |================ | 22% | |================ | 23% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |=================== | 27% | |=================== | 28% | |==================== | 28% | |==================== | 29% | |===================== | 29% | |===================== | 30% | |===================== | 31% | |====================== | 31% | |====================== | 32% | |======================= | 32% | |======================= | 33% | |======================= | 34% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 37% | |========================== | 38% | |=========================== | 38% | |=========================== | 39% | |============================ | 39% | |============================ | 40% | |================================== | 48% | |================================== | 49% | |=================================== | 49% | |=================================== | 50% | |=================================== | 51% | |==================================== | 51% | |==================================== | 52% | |===================================== | 52% | |===================================== | 53% | |===================================== | 54% | |====================================== | 54% | |====================================== | 55% | |======================================= | 55% | |======================================= | 56% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 59% | |========================================== | 60% | |========================================== | 61% | |=========================================== | 61% | |=========================================== | 62% | |============================================ | 62% | |============================================ | 63% | |============================================= | 64% | |============================================= | 65% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 67% | |================================================ | 68% | |================================================ | 69% | |================================================= | 69% | |================================================= | 70% | |================================================= | 71% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 72% | |=================================================== | 73% | |=================================================== | 74% | |==================================================== | 74% | |==================================================== | 75% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 77% | |====================================================== | 78% | |======================================================= | 78% | |======================================================= | 79% | |======================================================== | 79% | |======================================================== | 80% | |======================================================== | 81% | |========================================================= | 81% | |========================================================= | 82% | |========================================================== | 82% | |========================================================== | 83% | |========================================================== | 84% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 86% | |============================================================= | 87% | |============================================================= | 88% | |============================================================== | 88% | |============================================================== | 89% | |=============================================================== | 89% | |=============================================================== | 90% | |=============================================================== | 91% | |================================================================ | 91% | |================================================================ | 92% | |================================================================= | 92% | |================================================================= | 93% | |================================================================= | 94% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |===================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 99% | |======================================================================| 100% - -``` r -## preview -mapview(countyIncome, zcol = "B19019_001E") -``` - -![](module-examples-complete_files/figure-gfm/median-income-1-1.png) - -Notice how we needed to specify `_001E` for `zcol`. That references the -specific variable we want to map - variable 1 in the table’s estimate -(or `E`). The `M` values refer to the margin of the error - we expect -this estimate to be off by some amount within +/- this value. - -We can also download a specific column, like the median income for -one-person households (`B19019_002`): - -``` r -## download -countyIncome <- get_acs(geography = "county", year = 2019, state = 29, - variables = "B19019_002", output = "wide", - geometry = TRUE) -``` - - ## Getting data from the 2015-2019 5-year ACS - - ## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`. - -``` r -## preview -mapview(countyIncome, zcol = "B19019_002E") -``` - -![](module-examples-complete_files/figure-gfm/median-income-2-1.png) - -## Combining Data Sources - -Perhaps we have a range of data that we want to include. For this -example, we’ll download data on median income and the proportion of -women in tracts in Boone County, Missouri. We’ll download the income -data with `geometry = TRUE` and the sex data with `geometry = FALSE`: - -``` r -## download -booneIncome <- get_acs(geography = "tract", year = 2019, state = 29, - county = "019", variables = "B19019_001", - output = "wide", geometry = TRUE) %>% - rename(median_income = B19019_001E) %>% - select(GEOID, median_income) -``` - - ## Getting data from the 2015-2019 5-year ACS - - ## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`. - - ## | | | 0% | |= | 1% | |== | 3% | |=== | 4% | |==== | 5% | |===== | 7% | |====== | 8% | |====== | 9% | |======= | 11% | |======== | 12% | |========= | 13% | |========== | 15% | |=========== | 16% | |============ | 17% | |============= | 19% | |============== | 20% | |=============== | 21% | |================ | 23% | |================= | 24% | |================== | 25% | |=================== | 27% | |==================== | 28% | |===================== | 29% | |===================== | 31% | |====================== | 32% | |======================= | 33% | |======================== | 35% | |========================= | 36% | |========================== | 37% | |=========================== | 39% | |============================ | 40% | |============================= | 41% | |============================== | 43% | |=============================== | 44% | |================================ | 46% | |================================= | 47% | |================================== | 49% | |=================================== | 50% | |==================================== | 51% | |===================================== | 53% | |====================================== | 54% | |======================================= | 55% | |======================================== | 57% | |========================================= | 58% | |========================================== | 59% | |========================================== | 61% | |=========================================== | 62% | |============================================= | 65% | |============================================== | 66% | |=============================================== | 67% | |================================================ | 69% | |================================================= | 70% | |================================================== | 71% | |=================================================== | 73% | |==================================================== | 74% | |==================================================== | 75% | |===================================================== | 76% | |======================================================= | 78% | |======================================================== | 79% | |======================================================== | 80% | |========================================================= | 81% | |========================================================== | 83% | |============================================================= | 87% | |=============================================================== | 90% | |=============================================================== | 91% | |=================================================================== | 96% | |==================================================================== | 97% | |======================================================================| 99% | |======================================================================| 100% - -``` r -## download -booneSex <- get_acs(geography = "tract", year = 2019, state = 29, - county = "019", variables = c("B01001_001", "B01001_026"), - output = "wide") %>% - mutate(pct_women = B01001_026E/B01001_001E*100) %>% - select(GEOID, pct_women) -``` - - ## Getting data from the 2015-2019 5-year ACS - -To combine these data, we’ll use `left_join()` from `dplyr`. Our `sf` -object should always be the first object in the join (the `x` data) and -our non-sf data should be the second data (the `y` data): - -``` r -boone <- left_join(booneIncome, booneSex, by = "GEOID") -``` - -Three common issues arise: - -1. The ID columns are named differently: `by = c("GEOID" = "geoid")` -2. The ID columns are different type: - `booneIncome <- mutate(GEOID = as.numeric(GEOID))` -3. Both objects are `sf` objects: `st_geometry(booneSEX) <- NULL` - -## Using Tigris - -To get data from the TIGER/line database, we can use the `tigris` -package. You can see a full list of the data available -[here](https://cran.r-project.org/web/packages/tigris/tigris.pdf). - -### State Data - -We can download a generalized version, which smooths out state -boundaries so that the overall image is both smaller in disk size and -(sometimes) easier to read. This is particularly helpful if you are -making small scale maps of the entire United States. We’ll get these -data at the “20m” resolution using the `states()` function: - -``` r -states <- states(cb = TRUE, resolution = "20m") -``` - - ## | | | 0% | |====== | 9% | |======================== | 35% | |======================================================= | 79% | |============================================================= | 87% | |=================================================================== | 96% | |======================================================================| 100% - -### County Data - -Now, we’ll get more detailed data - all of the county boundaries for -Missouri. We’ll use the `counties()` function using a slightly less -generalized resolution, “5m”: - -``` r -moCounties <- counties(cb = TRUE, resolution = "5m") -``` - - ## | | | 0% | |= | 1% | |== | 2% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 6% | |===== | 7% | |====== | 8% | |====== | 9% | |======= | 10% | |======== | 11% | |======== | 12% | |========= | 13% | |========== | 14% | |========== | 15% | |=========== | 16% | |============ | 17% | |============= | 18% | |============== | 20% | |=============== | 21% | |=============== | 22% | |================ | 23% | |================= | 24% | |================= | 25% | |================== | 26% | |=================== | 27% | |=================== | 28% | |==================== | 28% | |==================== | 29% | |===================== | 30% | |====================== | 31% | |====================== | 32% | |======================= | 33% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 37% | |=========================== | 38% | |=========================== | 39% | |============================ | 40% | |============================= | 41% | |============================== | 42% | |============================== | 43% | |=============================== | 44% | |=============================== | 45% | |================================ | 46% | |================================= | 47% | |================================= | 48% | |================================== | 48% | |================================== | 49% | |=================================== | 50% | |=================================== | 51% | |==================================== | 51% | |==================================== | 52% | |====================================== | 54% | |====================================== | 55% | |======================================= | 55% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================== | 60% | |=========================================== | 61% | |=========================================== | 62% | |============================================ | 62% | |============================================ | 63% | |============================================= | 64% | |============================================= | 65% | |============================================== | 66% | |=============================================== | 67% | |================================================ | 69% | |================================================= | 70% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 73% | |==================================================== | 74% | |===================================================== | 76% | |====================================================== | 76% | |====================================================== | 77% | |====================================================== | 78% | |======================================================= | 78% | |======================================================= | 79% | |======================================================== | 79% | |======================================================== | 80% | |======================================================== | 81% | |========================================================= | 82% | |========================================================== | 83% | |========================================================== | 84% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 86% | |============================================================= | 87% | |============================================================= | 88% | |============================================================== | 88% | |=============================================================== | 90% | |=============================================================== | 91% | |================================================================ | 91% | |================================================================ | 92% | |================================================================= | 93% | |================================================================= | 94% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |===================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 100% - -### Tract Data - -Now, we’ll get even more detailed data - all of the tract boundaries for -St. Charles County, Missouri. We’ll use the `tracts()` function with -`cb = FALSE` by default: - -``` r -stCharlesTracts <- tracts(state = 29, county = 183) -``` - - ## | | | 0% | | | 1% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 9% | |======= | 10% | |======= | 11% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 17% | |============ | 18% | |============= | 18% | |============= | 19% | |============== | 19% | |============== | 20% | |============== | 21% | |=============== | 21% | |=============== | 22% | |================ | 22% | |================ | 23% | |================ | 24% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |=================== | 27% | |=================== | 28% | |==================== | 28% | |==================== | 29% | |===================== | 29% | |===================== | 30% | |===================== | 31% | |====================== | 31% | |====================== | 32% | |======================= | 32% | |======================= | 33% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 37% | |========================== | 38% | |=========================== | 38% | |=========================== | 39% | |============================ | 39% | |============================ | 40% | |============================ | 41% | |============================= | 41% | |============================= | 42% | |============================== | 42% | |============================== | 43% | |============================== | 44% | |=============================== | 44% | |=============================== | 45% | |================================ | 45% | |================================ | 46% | |================================= | 47% | |================================= | 48% | |================================== | 48% | |================================== | 49% | |=================================== | 49% | |=================================== | 50% | |=================================== | 51% | |==================================== | 51% | |==================================== | 52% | |===================================== | 52% | |===================================== | 53% | |===================================== | 54% | |====================================== | 54% | |====================================== | 55% | |======================================= | 55% | |======================================= | 56% | |======================================== | 56% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 59% | |========================================== | 60% | |========================================== | 61% | |=========================================== | 61% | |=========================================== | 62% | |============================================ | 62% | |============================================ | 63% | |============================================ | 64% | |============================================= | 64% | |============================================= | 65% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 67% | |=============================================== | 68% | |================================================ | 68% | |================================================ | 69% | |================================================= | 69% | |================================================= | 70% | |================================================= | 71% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 72% | |=================================================== | 73% | |==================================================== | 74% | |==================================================== | 75% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 76% | |====================================================== | 77% | |====================================================== | 78% | |======================================================= | 78% | |======================================================= | 79% | |======================================================== | 79% | |======================================================== | 80% | |======================================================== | 81% | |========================================================= | 81% | |========================================================= | 82% | |========================================================== | 82% | |========================================================== | 83% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 87% | |============================================================= | 88% | |============================================================== | 88% | |============================================================== | 89% | |=============================================================== | 89% | |=============================================================== | 90% | |=============================================================== | 91% | |================================================================ | 91% | |================================================================ | 92% | |================================================================= | 92% | |================================================================= | 93% | |================================================================= | 94% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |===================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 99% | |======================================================================| 100% diff --git a/examples/module-examples-complete.nb.html b/examples/module-examples-complete.nb.html deleted file mode 100644 index a35a4bf..0000000 --- a/examples/module-examples-complete.nb.html +++ /dev/null @@ -1,470 +0,0 @@ - - - - - - - - - - - - - - -Meeting Examples - Complete - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
knitr::opts_chunk$set(cache = FALSE)
- - - -
-

Introduction

-

This notebook illustrates data access through both tigris and tidycensus as well as joins using dplyr.

-
-
-

Dependencies

-

This notebook requires the following packages:

- - - -
# tidyverse packages
-library(dplyr)       # data wrangling
-
-# spatial packages
-library(mapview)     # preview geometric data
-library(sf)          # spatial tools
-library(tidycensus)  # demographic data
-library(tigris)      # tiger/line data
-
-# other packages
-library(here)        # file path management
- - - -
-
-

tidycensus Set-up

-

Before using tidycensus, you need to install a census API key. Use the syntax below, copied into your console, to install the key you received via email.

-
census_api_key("KEY", install = TRUE)
-

This is not a code chunk you will need in each notebook. As long as install = TRUE, you will only have to do this once!

-
-
-

Decennial Census Data

-
-

Get List of Variables

-

To get a preview of variables available in the get_decennial() function, we can use the load_variables() function:

- - - -
census <- load_variables(year = 2000, dataset = "sf1") 
- - - -

I find it useful to assign the output of this function to an object so that I can search through it. Try searching for the variable P0010001, the total population of a geographic unit, in the census object.

-
-
-

Download a Single Variable

-

To download data, we can use use the get_decennial() function to access, for example, population by state in 2000:

- - - -
popStates <- get_decennial(geography = "state", year = 2000, variable = "P001001")
- - - -

A full list of the geographies available in tidycensus can be found here.

-
-
-

Download a Full Table

-

Most variables in the decennial census are actually a part of a table. There are individual variables, for example, for race:

- - - - -

We rarely want to download these one at a time. Instead, we want to download them at one time into a single data frame. The table number for these data is P003 - we take the first four characters from the name variable.

- - - - -

We’ve used the FIPS codes for both Missouri (29) and St. Louis City (29510) here - you can find a full list of Missouri counties here.

-
-
-

Add Geometry

-

The tidycensus package also includes tools for downloading the geometries for these data as well. For instance, we can add geometric data to our previous call for City of St. Louis tract-level data on race by adding the geometry = TRUE argument:

- - - - -

Notice how I used the zcol argument for mapview() to preview a specific set of data as a thematic layer on the map! These data are not normalized, but we do get a quick preview of the distribution of Asian residents in St. Louis City.

-
-
-
-

Decennial Census Data

-
-

Get List of Variables

-

To get a preview of variables available in the get_acs() function, we can use the load_variables() function again. We’ll use "acs5" for our dataset and, for this example, we’ll pull from the most recent 2019 ACS year:

- - - - -

Try searching for the table B19013, the median household income table.

-
-
-

Get and Interpret ACS Data

-

We’ll illustrate get_acs() by using the data in table B19019. First, we’ll download these data as a full table for all counties in Missouri:

- - - - -

Notice how we needed to specify _001E for zcol. That references the specific variable we want to map - variable 1 in the table’s estimate (or E). The M values refer to the margin of the error - we expect this estimate to be off by some amount within +/- this value.

-

We can also download a specific column, like the median income for one-person households (B19019_002):

- - - - -
-
-
-

Combining Data Sources

-

Perhaps we have a range of data that we want to include. For this example, we’ll download data on median income and the proportion of women in tracts in Boone County, Missouri. We’ll download the income data with geometry = TRUE and the sex data with geometry = FALSE:

- - - - -

To combine these data, we’ll use left_join() from dplyr. Our sf object should always be the first object in the join (the x data) and our non-sf data should be the second data (the y data):

- - - - -

Three common issues arise:

-
    -
  1. The ID columns are named differently: by = c("GEOID" = "geoid")
  2. -
  3. The ID columns are different type: booneIncome <- mutate(GEOID = as.numeric(GEOID))
  4. -
  5. Both objects are sf objects: st_geometry(booneSEX) <- NULL
  6. -
-
-
-

Using Tigris

-

To get data from the TIGER/line database, we can use the tigris package. You can see a full list of the data available here.

-
-

State Data

-

We can download a generalized version, which smooths out state boundaries so that the overall image is both smaller in disk size and (sometimes) easier to read. This is particularly helpful if you are making small scale maps of the entire United States. We’ll get these data at the “20m” resolution using the states() function:

- - - - -
-
-

County Data

-

Now, we’ll get more detailed data - all of the county boundaries for Missouri. We’ll use the counties() function using a slightly less generalized resolution, “5m”:

- - - - -
-
-

Tract Data

-

Now, we’ll get even more detailed data - all of the tract boundaries for St. Charles County, Missouri. We’ll use the tracts() function with cb = FALSE by default:

- - - - - -
-
- -
LS0tCnRpdGxlOiAiTWVldGluZyBFeG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- - - - - - diff --git a/examples/module-examples-complete_files/figure-gfm/median-income-1-1.png b/examples/module-examples-complete_files/figure-gfm/median-income-1-1.png deleted file mode 100644 index 459009f..0000000 Binary files a/examples/module-examples-complete_files/figure-gfm/median-income-1-1.png and /dev/null differ diff --git a/examples/module-examples-complete_files/figure-gfm/median-income-2-1.png b/examples/module-examples-complete_files/figure-gfm/median-income-2-1.png deleted file mode 100644 index 187c9fb..0000000 Binary files a/examples/module-examples-complete_files/figure-gfm/median-income-2-1.png and /dev/null differ diff --git a/examples/module-examples-complete_files/figure-gfm/unnamed-chunk-1-1.png b/examples/module-examples-complete_files/figure-gfm/unnamed-chunk-1-1.png deleted file mode 100644 index d21e1cc..0000000 Binary files a/examples/module-examples-complete_files/figure-gfm/unnamed-chunk-1-1.png and /dev/null differ diff --git a/examples/module-examples.nb.html b/examples/module-examples.nb.html deleted file mode 100644 index 170712e..0000000 --- a/examples/module-examples.nb.html +++ /dev/null @@ -1,488 +0,0 @@ - - - - - - - - - - - - - - -Meeting Examples - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - -
-

Introduction

-

This notebook illustrates data access through both tigris and tidycensus as well as joins using dplyr.

-
-
-

Dependencies

-

This notebook requires the following packages:

- - - -
# tidyverse packages
-library(dplyr)       # data wrangling
-
-# spatial packages
-library(mapview)     # preview geometric data
-library(sf)          # spatial tools
-library(tidycensus)  # demographic data
-library(tigris)      # tiger/line data
-
-# other packages
-library(here)        # file path management
- - - -
-
-

tidycensus Set-up

-

Before using tidycensus, you need to install a census API key. Use the syntax below, copied into your console, to install the key you received via email.

-
census_api_key("KEY", install = TRUE)
-

This is not a code chunk you will need in each notebook. As long as install = TRUE, you will only have to do this once!

-
-
-

Decennial Census Data

-
-

Get List of Variables

-

To get a preview of variables available in the get_decennial() function, we can use the load_variables() function:

- - - - -

I find it useful to assign the output of this function to an object so that I can search through it. Try searching for the variable P0010001, the total population of a geographic unit, in the census object.

-
-
-

Download a Single Variable

-

To download data, we can use use the get_decennial() function to access, for example, population by state in 2000:

- - - - -

A full list of the geographies available in tidycensus can be found here.

-
-
-

Download a Full Table

-

Most variables in the decennial census are actually a part of a table. There are individual variables, for example, for race:

- - - -
census %>%
-  filter(concept == "P3. RACE [8]")
- - - -

We rarely want to download these one at a time. Instead, we want to download them at one time into a single data frame. The table number for these data is P003 - we take the first four characters from the name variable.

- - - - -

We’ve used the FIPS codes for both Missouri (29) and St. Louis City (29510) here - you can find a full list of Missouri counties here.

-
-
-

Add Geometry

-

The tidycensus package also includes tools for downloading the geometries for these data as well. For instance, we can add geometric data to our previous call for City of St. Louis tract-level data on race by adding the geometry = TRUE argument:

- - - - -

Notice how I used the zcol argument for mapview() to preview a specific set of data as a thematic layer on the map! These data are not normalized, but we do get a quick preview of the distribution of Asian residents in St. Louis City.

-
-
-
-

Decennial Census Data

-
-

Get List of Variables

-

To get a preview of variables available in the get_acs() function, we can use the load_variables() function again. We’ll use "acs5" for our dataset and, for this example, we’ll pull from the most recent 2019 ACS year:

- - - - -

Try searching for the table B19013, the median household income table.

-
-
-

Get and Interpret ACS Data

-

We’ll illustrate get_acs() by using the data in table B19019. First, we’ll download these data as a full table for all counties in Missouri:

- - - -
## download
-
-
-## preview
-mapview(countyIncome, zcol = "")
- - - -

Notice how we needed to specify _001E for zcol. That references the specific variable we want to map - variable 1 in the table’s estimate (or E). The M values refer to the margin of the error - we expect this estimate to be off by some amount within +/- this value.

-

We can also download a specific column, like the median income for one-person households (B19019_002):

- - - -
## download
-
-
-## preview
-mapview(countyIncome, zcol = "")
- - - -
-
-
-

Combining Data Sources

-

Perhaps we have a range of data that we want to include. For this example, we’ll download data on median income and the proportion of women in tracts in Boone County, Missouri. We’ll download the income data with geometry = TRUE and the sex data with geometry = FALSE:

- - - -
## download
-booneIncome <- get_acs(geography = "tract", year = 2019, state = 29,
-                       county = "019", variables = "B19019_001", 
-                       output = "wide", geometry = TRUE) %>%
-  rename(median_income = B19019_001E) %>%
-  select(GEOID, median_income)
-
-## download
-booneSex <- get_acs(geography = "tract", year = 2019, state = 29,
-                       county = "019", variables = c("B01001_001", "B01001_026"),
-                       output = "wide") %>%
-  mutate(pct_women = B01001_026E/B01001_001E*100) %>%
-  select(GEOID, pct_women)
- - - -

To combine these data, we’ll use left_join() from dplyr. Our sf object should always be the first object in the join (the x data) and our non-sf data should be the second data (the y data):

- - - - -

Three common issues arise:

-
    -
  1. The ID columns are named differently: by = c("GEOID" = "geoid")
  2. -
  3. The ID columns are different type: booneIncome <- mutate(GEOID = as.numeric(GEOID))
  4. -
  5. Both objects are sf objects: st_geometry(booneSEX) <- NULL
  6. -
-
-
-

Using Tigris

-

To get data from the TIGER/line database, we can use the tigris package. You can see a full list of the data available here.

-
-

State Data

-

We can download a generalized version, which smooths out state boundaries so that the overall image is both smaller in disk size and (sometimes) easier to read. This is particularly helpful if you are making small scale maps of the entire United States. We’ll get these data at the “20m” resolution using the states() function:

- - - - -
-
-

County Data

-

Now, we’ll get more detailed data - all of the county boundaries for Missouri. We’ll use the counties() function using a slightly less generalized resolution, “5m”:

- - - - -
-
-

Tract Data

-

Now, we’ll get even more detailed data - all of the tract boundaries for St. Charles County, Missouri. We’ll use the tracts() function with cb = FALSE by default:

- - - -
-
- -
LS0tCnRpdGxlOiAiTWVldGluZyBFeGFtcGxlcyIKYXV0aG9yOiAiQ2hyaXN0b3BoZXIgUHJlbmVyLCBQaEQiCmRhdGU6ICcoYHIgZm9ybWF0KFN5cy50aW1lKCksICIlQiAlZCwgJVkiKWApJwpvdXRwdXQ6IAogIGdpdGh1Yl9kb2N1bWVudDogZGVmYXVsdAogIGh0bWxfbm90ZWJvb2s6IGRlZmF1bHQgCi0tLQoKIyMgSW50cm9kdWN0aW9uClRoaXMgbm90ZWJvb2sgaWxsdXN0cmF0ZXMgZGF0YSBhY2Nlc3MgdGhyb3VnaCBib3RoIGB0aWdyaXNgIGFuZCBgdGlkeWNlbnN1c2AgYXMgd2VsbCBhcyBqb2lucyB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