Make Your Maps in QGIS but use R and Tidycensus to Generate Census Shapefiles πŸ—Ί

Make Your Maps in QGIS but use R and Tidycensus to Generate Census Shapefiles πŸ—Ί

Why choose when you can have it all? Seriously, QGIS makes it easy to move labels as you like and do the styling of the Shapefile or GeoPackage you generate in R with tidycensus and sf.

library(tidycensus)
library(sf)
lowincome <- get_acs(
  geography = “state”,
  table = ‘B19001’,
  year = 2020,
  output = ‘wide’,
  survey = “acs5”,
  geometry = TRUE);
lowincome$under30k <- ((lowincome$B19001_002E +lowincome$B19001_003E+ lowincome$B19001_004E+ lowincome$B19001_005E+ lowincome$B19001_006E) /lowincome$B19001_001E)*100
lowincome %>% write_sf(‘/tmp/under30k.gpkg’)

With the above R code, it will generate a GeoPackage (use extension .gpkg) or Shapefile (use extension .shp) you can use to make your map in QGIS. Then in QGIS if you want to simplify the output, you can use a geometry generator in the styles:

simplify($geometry,0.003)

Or you can specify the simplification in the R script when you run get_acs(), as it is a wrapper around the tigris package:

lowincome <- get_acs(
  geography = “state”,
  table = ‘B19001’,
  year = 2020,
  output = ‘wide’,
  survey = “acs5”,
  geometry = TRUE,
  resolution = ’20m’,
);

Neat ! R and QGIS are great tool to use together.

Leave a Reply

Your email address will not be published. Required fields are marked *