\n","author":{"@type":"Person","name":"BLP92"},"upvoteCount":0,"answerCount":0,"acceptedAnswer":null}}
Reputation: 301
I've pulled US census data by block and merged the block shapefile on it manually with the sf
and rgdal
packages. When I plot the resulting sf
object it's showing a skewed map despite the crs
remaining the same from the read-in of the shapefile through the merge.
The shapefiles can be found here: https://www2.census.gov/geo/tiger/TIGER_RD18/LAYER/TABBLOCK20/, the one for Illinois that I'm using is tl_rd22_17_tabblock20.zip
.
The census data can be found here: https://data.census.gov/table?q=population&g=0500000US17031$1000000&tid=DECENNIALPL2020.P1
Here's what should be a MWE:
library(ggplot2)
library(sf)
library(rgdal)
library(data.table)
dt_census <- fread(path_to_census_data)
blck_shp <- readOGR(dsn = block_shapefile_filepath, layer = "tl_rd22_17tabblock20")
blck_sf <- st_as_sf(blck_shp)
dt <- merge(blck_sf,dt_census, by.x = "GEOID20", by.y = "GEOID")
mini_dt <- dt[,c("POP20","geometry")]
mini_dt$POP20 <- as.numeric(mini_dt$POP20)
plot(mini_dt)
but this produces a skewed plot where some blocks on the northeast are clearly outside of city lines and into Lake Michigan.
Upvotes: 0
Views: 44