Skip to content

Instantly share code, notes, and snippets.

@juliasilge
Created May 12, 2021 03:34
Show Gist options
  • Save juliasilge/17bd01e3c749b0e966658820cb7fbfb7 to your computer and use it in GitHub Desktop.
Save juliasilge/17bd01e3c749b0e966658820cb7fbfb7 to your computer and use it in GitHub Desktop.
#TidyTuesday internet access in the US
library(tidyverse)
library(tidycensus)
library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1
library(viridis)
#> Loading required package: viridisLite
library(patchwork)
theme_set(silgelib::theme_plex())


broadband <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-05-11/broadband.csv')
#> 
#> ── Column specification ────────────────────────────────────────────────────────
#> cols(
#>   ST = col_character(),
#>   `COUNTY ID` = col_double(),
#>   `COUNTY NAME` = col_character(),
#>   `BROADBAND AVAILABILITY PER FCC` = col_character(),
#>   `BROADBAND USAGE` = col_character()
#> )
tx_broadband <- broadband %>%
    filter(ST == "TX") %>%
    transmute(GEOID = as.character(`COUNTY ID`),
              availability = parse_number(`BROADBAND AVAILABILITY PER FCC`),
              usage = parse_number(`BROADBAND USAGE`))
#> Warning: 6 parsing failures.
#> row col expected actual
#>  53  -- a number      -
#> 106  -- a number      -
#> 118  -- a number      -
#> 207  -- a number      -
#> 216  -- a number      -
#> ... ... ........ ......
#> See problems(...) for more details.

household_income <- get_acs(geography = "county", 
                            variables = "B19013_001", 
                            state = "TX",
                            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%  |                                                                              |=====                                                                 |   7%  |                                                                              |=====                                                                 |   8%  |                                                                              |======                                                                |   8%  |                                                                              |======                                                                |   9%  |                                                                              |=======                                                               |  10%  |                                                                              |=======                                                               |  11%  |                                                                              |========                                                              |  11%  |                                                                              |========                                                              |  12%  |                                                                              |=========                                                             |  12%  |                                                                              |=========                                                             |  13%  |                                                                              |==========                                                            |  14%  |                                                                              |==========                                                            |  15%  |                                                                              |===========                                                           |  15%  |                                                                              |===========                                                           |  16%  |                                                                              |============                                                          |  17%  |                                                                              |============                                                          |  18%  |                                                                              |=============                                                         |  18%  |                                                                              |=============                                                         |  19%  |                                                                              |==============                                                        |  19%  |                                                                              |==============                                                        |  20%  |                                                                              |===============                                                       |  21%  |                                                                              |===============                                                       |  22%  |                                                                              |================                                                      |  22%  |                                                                              |================                                                      |  23%  |                                                                              |================                                                      |  24%  |                                                                              |=================                                                     |  24%  |                                                                              |=================                                                     |  25%  |                                                                              |==================                                                    |  25%  |                                                                              |==================                                                    |  26%  |                                                                              |===================                                                   |  27%  |                                                                              |===================                                                   |  28%  |                                                                              |====================                                                  |  28%  |                                                                              |====================                                                  |  29%  |                                                                              |=====================                                                 |  30%  |                                                                              |======================                                                |  31%  |                                                                              |======================                                                |  32%  |                                                                              |=======================                                               |  33%  |                                                                              |========================                                              |  34%  |                                                                              |========================                                              |  35%  |                                                                              |=========================                                             |  35%  |                                                                              |=========================                                             |  36%  |                                                                              |==========================                                            |  37%  |                                                                              |===========================                                           |  38%  |                                                                              |===========================                                           |  39%  |                                                                              |============================                                          |  39%  |                                                                              |============================                                          |  40%  |                                                                              |============================                                          |  41%  |                                                                              |=============================                                         |  41%  |                                                                              |=============================                                         |  42%  |                                                                              |==============================                                        |  43%  |                                                                              |===============================                                       |  44%  |                                                                              |===============================                                       |  45%  |                                                                              |================================                                      |  45%  |                                                                              |================================                                      |  46%  |                                                                              |=================================                                     |  47%  |                                                                              |==================================                                    |  48%  |                                                                              |==================================                                    |  49%  |                                                                              |===================================                                   |  49%  |                                                                              |===================================                                   |  50%  |                                                                              |====================================                                  |  51%  |                                                                              |====================================                                  |  52%  |                                                                              |=====================================                                 |  52%  |                                                                              |=====================================                                 |  53%  |                                                                              |======================================                                |  54%  |                                                                              |=======================================                               |  56%  |                                                                              |========================================                              |  57%  |                                                                              |=========================================                             |  59%  |                                                                              |==========================================                            |  60%  |                                                                              |============================================                          |  63%  |                                                                              |=============================================                         |  64%  |                                                                              |================================================                      |  68%  |                                                                              |=================================================                     |  70%  |                                                                              |=================================================                     |  71%  |                                                                              |==================================================                    |  71%  |                                                                              |===========================================================           |  85%  |                                                                              |=============================================================         |  87%  |                                                                              |==============================================================        |  89%  |                                                                              |===============================================================       |  91%  |                                                                              |=================================================================     |  92%  |                                                                              |=================================================================     |  93%  |                                                                              |====================================================================  |  97%  |                                                                              |===================================================================== |  98%  |                                                                              |======================================================================| 100%


tx_joined <- household_income %>%
    left_join(tx_broadband)
#> Joining, by = "GEOID"

tx_joined
#> Simple feature collection with 254 features and 7 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -106.6456 ymin: 25.83738 xmax: -93.50829 ymax: 36.5007
#> Geodetic CRS:  NAD83
#> First 10 features:
#>    GEOID                     NAME   variable estimate   moe availability usage
#> 1  48081       Coke County, Texas B19013_001    45000  6161         0.70  0.06
#> 2  48273    Kleberg County, Texas B19013_001    43730  2990         1.00  0.23
#> 3  48203   Harrison County, Texas B19013_001    52220  2366         0.77  0.22
#> 4  48223    Hopkins County, Texas B19013_001    52078  2235         0.60  0.33
#> 5  48033     Borden County, Texas B19013_001    72188 20611         0.30  0.01
#> 6  48419     Shelby County, Texas B19013_001    42522  3515         0.12  0.04
#> 7  48067       Cass County, Texas B19013_001    44848  3153         0.52  0.10
#> 8  48025        Bee County, Texas B19013_001    44578  5310         1.00  0.26
#> 9  48339 Montgomery County, Texas B19013_001    80902  1599         0.99  0.64
#> 10 48029      Bexar County, Texas B19013_001    57157   491         1.00  0.58
#>                          geometry
#> 1  MULTIPOLYGON (((-100.825 31...
#> 2  MULTIPOLYGON (((-97.3178 27...
#> 3  MULTIPOLYGON (((-94.70215 3...
#> 4  MULTIPOLYGON (((-95.86333 3...
#> 5  MULTIPOLYGON (((-101.6913 3...
#> 6  MULTIPOLYGON (((-94.51143 3...
#> 7  MULTIPOLYGON (((-94.65384 3...
#> 8  MULTIPOLYGON (((-98.08976 2...
#> 9  MULTIPOLYGON (((-95.83024 3...
#> 10 MULTIPOLYGON (((-98.80655 2...

plot_tx <- function(variable) {
    tx_joined %>%
        st_as_sf() %>%
        ggplot(aes(fill = {{variable}}, color = {{variable}})) + 
        geom_sf() + 
        coord_sf() + 
        scale_fill_viridis() + 
        scale_color_viridis() +
        theme(legend.position = "none")
}

plot_tx(estimate) + labs(subtitle = "Income") + 
    plot_tx(usage) + labs(subtitle = "Broadband usage") +
    plot_annotation(title = "Median household income and broadband usage in Texas",
                    subtitle = "Both income and internet usage are highest in cities")

Created on 2021-05-11 by the reprex package (v2.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment