0

Can you use the resolution argument in get_acs() to filter out the small islands in the Hawaiian archipelago?

I might have found a bug in tidycensus, one of my favorite packages.

I was mapping U.S congressional districts using tidycensus's get_acs() function, but I was getting that long archipelago northwest of Hawaii. I tried following Kyle Walker's tip to include the resolution = "20m" argument to filter out the small islands, but the archipelago wouldn't go away. I eventually just grabbed the geometry using the congressional_districts() function and joined the get_acs() data.

MRE:

#map with too many islands
cds <- get_acs(
  geography = "congressional district",
  variables = "B01003_001",
  geometry = TRUE,
  resolution = "20m"
) %>% shift_geometry()

cds %>%
  ggplot() +
  geom_sf()

Bad map:

img1

What worked:

#map with the right number of islands
cds2 <- congressional_districts(cb = TRUE,
                                resolution = "20m") %>% shift_geometry()

cds2 %>%
  ggplot() +
  geom_sf()

Good map:

img2

camille
  • 16,432
  • 18
  • 38
  • 60
  • This doesn't seem like a bug in the package, just a matter of you changing function arguments. `tidycensus` calls that return geometries use calls from the `tigris` package, which downloads shapefiles from the Census Bureau [TIGER files](https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.html). These come in 2 types: more detailed shapes, or less-detailed [cartographic boundary files](https://www.census.gov/programs-surveys/geography/technical-documentation/naming-convention/cartographic-boundary-file.html), corresponding to `tigris`'s `cb` argument... – camille Feb 19 '22 at 18:34
  • For most tigris functions, the default is `cb = FALSE`, meaning the more detailed shapes are downloaded. That was the argument used in your first case. In your second, when you changed to `cb = TRUE`, you downloaded the less detailed version, the CB file, which doesn't retain those very small areas. AFAIK the `resolution` argument only pertains to the CB files. from the tigris docs: "The resolution of the cartographic boundary file (if cb == TRUE). Defaults to '500k'; options include '5m' (1:5 million) and '20m' (1:20 million)." – camille Feb 19 '22 at 18:36
  • Actually, my 2nd comment isn't totally correct. `tidycensus:::use_tigris` calls tigris functions with a default `cb = TRUE`, in contrast to most tigris functions' own defaults. CB files still have those small islands; it appears where they get lost is in `shift_geometry` [here](https://github.com/walkerke/tigris/blob/227b8fda7af9a35baf50bf07fdf539fb08afa9ea/R/shift_geometry.R#L229) with rescaling and intersecting geometries. All that is to say that if you want geometries altered in a specific way, such as filtering them, you should probably do that yourself separately – camille Feb 19 '22 at 19:04

1 Answers1

0

I fixed this in the latest CRAN release of tigris (sent it in last week); if you re-install tigris your original code will return the desired results.

kwalkertcu
  • 1,011
  • 6
  • 8