School-district-level estimates in Tennessee of how many people under age 18 have no access at home to the internet and to a computer. Source: 2018-2022 Five-Year American Community Survey. See also the raw data extracted by this script.
#install.packages("tidyverse")
#install.packages("tidycensus")
#install.packages("sf")
#install.packages("mapview")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidycensus)
library(sf)
## Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
library(mapview)
mapviewOptions(basemaps.color.shuffle = FALSE)
#census_api_key("PasteYourAPIKeyBetweenTheseQuoteMarks")
DetailedTables <- load_variables(2022, "acs5", cache = TRUE)
SubjectTables <- load_variables(2022, "acs5/subject", cache = TRUE)
ProfileTables <- load_variables(2022, "acs5/profile", cache = TRUE)
ChosenVars <- filter(
SubjectTables,
name == "S2802_C06_002" |
name == "S2802_C04_002" |
name == "S0101_C01_022"
)
print(ChosenVars$name)
## [1] "S0101_C01_022" "S2802_C04_002" "S2802_C06_002"
print(ChosenVars$label)
## [1] "Estimate!!Total!!Total population!!SELECTED AGE CATEGORIES!!Under 18 years"
## [2] "Estimate!!Without an Internet Subscription!!With a computer!!Total population in households!!AGE!!Under 18 years"
## [3] "Estimate!!No computer in household!!Total population in households!!AGE!!Under 18 years"
Secondary <- get_acs(
geography = "school district (secondary)",
state = "TN",
variables = c(
Under18NoComp_ = "S2802_C06_002",
Under18NoNet_ = "S2802_C04_002",
Under18_ = "S0101_C01_022"
),
year = 2022,
survey = "acs5",
output = "wide",
geometry = TRUE
)
## Getting data from the 2018-2022 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Subject Tables
##
|
| | 0%
|
|===================== | 30%
|
|================================ | 46%
|
|====================================================== | 77%
|
|======================================================================| 100%
Unified <- get_acs(
geography = "school district (unified)",
state = "TN",
variables = c(
Under18NoComp_ = "S2802_C06_002",
Under18NoNet_ = "S2802_C04_002",
Under18_ = "S0101_C01_022"
),
year = 2022,
survey = "acs5",
output = "wide",
geometry = TRUE
)
## Getting data from the 2018-2022 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Subject Tables
##
|
| | 0%
|
|======= | 9%
|
|======== | 12%
|
|========== | 15%
|
|============ | 18%
|
|============= | 19%
|
|================ | 22%
|
|================= | 24%
|
|=================== | 27%
|
|===================== | 30%
|
|====================== | 31%
|
|======================== | 34%
|
|========================= | 36%
|
|=========================== | 39%
|
|============================= | 42%
|
|============================== | 43%
|
|================================= | 48%
|
|=================================== | 51%
|
|======================================= | 55%
|
|============================================ | 63%
|
|============================================== | 66%
|
|==================================================== | 75%
|
|======================================================= | 79%
|
|========================================================== | 84%
|
|=============================================================== | 90%
|
|================================================================ | 91%
|
|======================================================================| 100%
mydata <- rbind(Unified, Secondary)
mydata <-
separate_wider_delim(mydata,
NAME,
delim = ", ",
names = c("District", "State"))
mydata_sf <- st_as_sf(mydata)
No_Net <- mapview(
mydata_sf,
zcol = "Under18NoNet_E",
col.regions = RColorBrewer::brewer.pal(9, "Blues"),
alpha.regions = .5,
layer.name = "<18, no internet",
#Customizable
popup = TRUE
)
No_Net
No_Comp <- mapview(
mydata_sf,
zcol = "Under18NoComp_E",
col.regions = RColorBrewer::brewer.pal(9, "Blues"),
alpha.regions = .5,
layer.name = "<18, no computer",
#Customizable
popup = TRUE
)
No_Comp
RawData <- st_drop_geometry(mydata_sf)
write.csv(RawData,"RawData.csv")
mydata <- filter(
mydata,
District == "Metropolitan Nashville Public School District" |
District == "Robertson County School District" |
District == "Cheatham County School District" |
District == "Williamson County School District" |
District == "Rutherford County School District" |
District == "Wilson County School District" |
District == "Sumner County School District" |
District == "Williamson County School District in Franklin" |
District == "Rutherford County School District in Murfreesboro" |
District == "Wilson County School District in Lebanon"
)
mydata_sf <- st_as_sf(mydata)
No_Net <- mapview(
mydata_sf,
zcol = "Under18NoNet_E",
col.regions = RColorBrewer::brewer.pal(9, "Blues"),
alpha.regions = .5,
layer.name = "<18, no internet",
#Customizable
popup = TRUE
)
No_Net
No_Comp <- mapview(
mydata_sf,
zcol = "Under18NoComp_E",
col.regions = RColorBrewer::brewer.pal(9, "Blues"),
alpha.regions = .5,
layer.name = "<18, no computer",
#Customizable
popup = TRUE
)
No_Comp
Just the script:
#install.packages("tidyverse")
#install.packages("tidycensus")
#install.packages("sf")
#install.packages("mapview")
library(tidyverse)
library(tidycensus)
library(sf)
library(mapview)
mapviewOptions(basemaps.color.shuffle = FALSE)
#census_api_key("PasteYourAPIKeyBetweenTheseQuoteMarks")
DetailedTables <- load_variables(2022, "acs5", cache = TRUE)
SubjectTables <- load_variables(2022, "acs5/subject", cache = TRUE)
ProfileTables <- load_variables(2022, "acs5/profile", cache = TRUE)
ChosenVars <- filter(SubjectTables,name == "S2802_C06_002"|
name == "S2802_C04_002"|
name == "S0101_C01_022")
print(ChosenVars$name)
print(ChosenVars$label)
Secondary <- get_acs(
geography = "school district (secondary)",
state = "TN",
variables = c(Under18NoComp_ = "S2802_C06_002",
Under18NoNet_ = "S2802_C04_002",
Under18_ = "S0101_C01_022"),
year = 2022,
survey = "acs5",
output = "wide",
geometry = TRUE)
Unified <- get_acs(
geography = "school district (unified)",
state = "TN",
variables = c(Under18NoComp_ = "S2802_C06_002",
Under18NoNet_ = "S2802_C04_002",
Under18_ = "S0101_C01_022"),
year = 2022,
survey = "acs5",
output = "wide",
geometry = TRUE)
mydata <- rbind(Unified,Secondary)
mydata <-
separate_wider_delim(mydata,
NAME,
delim = ", ",
names = c("District", "State"))
mydata_sf <- st_as_sf(mydata)
No_Net <- mapview(mydata_sf, zcol = "Under18NoNet_E",
col.regions = RColorBrewer::brewer.pal(9, "Blues"), alpha.regions = .5,
layer.name = "<18, no internet",#Customizable
popup = TRUE)
No_Net
No_Comp <- mapview(mydata_sf, zcol = "Under18NoComp_E",
col.regions = RColorBrewer::brewer.pal(9, "Blues"), alpha.regions = .5,
layer.name = "<18, no computer",#Customizable
popup = TRUE)
No_Comp
RawData <- st_drop_geometry(mydata_sf)
write.csv(RawData,"RawData.csv")
mydata <- filter(
mydata,
District == "Metropolitan Nashville Public School District" |
District == "Robertson County School District" |
District == "Cheatham County School District" |
District == "Williamson County School District" |
District == "Rutherford County School District" |
District == "Wilson County School District" |
District == "Sumner County School District" |
District == "Williamson County School District in Franklin" |
District == "Rutherford County School District in Murfreesboro" |
District == "Wilson County School District in Lebanon")
mydata_sf <- st_as_sf(mydata)
No_Net <- mapview(mydata_sf, zcol = "Under18NoNet_E",
col.regions = RColorBrewer::brewer.pal(9, "Blues"), alpha.regions = .5,
layer.name = "<18, no internet",#Customizable
popup = TRUE)
No_Net
No_Comp <- mapview(mydata_sf, zcol = "Under18NoComp_E",
col.regions = RColorBrewer::brewer.pal(9, "Blues"), alpha.regions = .5,
layer.name = "<18, no computer",#Customizable
popup = TRUE)
No_Comp