Abrina Williams
Abrina Williams

Reputation: 11

Can I map specific blocks using Tidycensus and Tigris?

I'm trying to map data for four blocks using R packages Tidycensus and Tigris. I wonder if it possible to specify the blocks you want to map, or if one must map the entire County? Could I add a line to the above code to specify the blocks I want to map, Geoid's of there blocks are: 220710117004001, 220710117004021, 220710039002015, and220710006062021?

Upvotes: 1

Views: 149

Answers (1)

kwalkertcu
kwalkertcu

Reputation: 1061

You can't request data for individual blocks at a time, but you can pull down by county and filter for the blocks you need with dplyr::filter(). If you use shapefile caching with options(tigris_use_cache = TRUE), the first download will be slow but subsequent runs will go quickly.

library(tidycensus)
library(dplyr)
library(mapview)
options(tigris_use_cache = TRUE)

block_pop <- get_decennial(
  geography = "block",
  variables = "P1_001N",
  year = 2020,
  state = "22",
  county = "071",
  geometry = TRUE
) %>%
  filter(GEOID %in% c("220710117004001", "220710117004021", 
                      "220710039002015", "220710006062021"))

mapview(block_pop)

enter image description here

Upvotes: 2

Related Questions