Counts of Tennesseans identifying their races as “Japanese,” by county.
Source: 2022 Five-Year American Community Survey
Code:
# Installing required packages
if (!require("tidyverse")) install.packages("tidyverse")
if (!require("tidycensus")) install.packages("tidycensus")
if (!require("sf")) install.packages("sf")
if (!require("mapview")) install.packages("mapview")
library(tidycensus)
library(tidyverse)
library(sf)
library(mapview)
options(tigris_use_cache = TRUE)
# NOTE: Obtain a Census API key from
# https://api.census.gov/data/key_signup.html
# and replace the census_api_key code line's
# PastYourAPIKeyBetwenTheseQuoteMarks text with your
# API key. Also, delete the "#" from the front of the
# census_api_key code.
#census_api_key("PasteYourAPIKeyBetwenTheseQuoteMarks")
# Getting ACS variable info
# Change "2021" to your preferred year.
# Change "acs1" to "acs5" if you want five-year data.
DetailedTables <- load_variables(2022, "acs5", cache = TRUE)
SubjectTables <- load_variables(2022, "acs5/subject", cache = TRUE)
ProfileTables <- load_variables(2022, "acs5/profile", cache = TRUE)
SubjectTables$geography <- "NA"
ProfileTables$geography <- "NA"
AllVariables <- rbind(DetailedTables,SubjectTables,ProfileTables)
rm(DetailedTables,SubjectTables,ProfileTables)
# When you have the name of the variable you want, paste it
# in place of "B01001_001" in both instances below.
# Replace "TN" with a different two-letter state
# abbreviation to get data for that state's counties.
# Getting the map data
MapData <- get_acs(geography = "county",
state = "TN",
variables = c(Japanese_ = "DP05_0048",
JapanesePCT_ = "DP05_0048P"),
year = 2022,
survey = "acs5",
output = "wide",
geometry = TRUE)
# Pruning any empty columns
# MapData <- MapData[colSums(!is.na(MapData)) > 0]
# Making preview maps
options(scipen=999)
mapview(MapData,zcol = "Japanese_E", popup = FALSE,
layer.name = "Japanese")