1

I want to create a zipcode map for Dallas. I have this shapefile which should include all postal codes within it (Street files)

I've been using this as a resource

below is an example of what I would like to create, and color the zipcode map in as well for certain regions I'm discussing at the time

enter image description here

memeium
  • 15
  • 1
  • 6
  • 2
    You have a shapefile and a tutorial, and presumably you have some data to display. So what's the question exactly? – camille Dec 31 '19 at 04:26
  • 1
    Coloring a single zipcode isn't something you included in the question at all. Try to make this a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that shows how far you've gotten and where you got stuck, because that isn't clear right now – camille Dec 31 '19 at 17:57

1 Answers1

2

The data isn't ideal for making something exactly like what you've linked to, but you can still get close.

After unzipping the downloaded data:

library(tidyverse)
library(sf)

dallas_streets <- sf_read('unzipped_folder/')
ggplot(sample_frac(dallas_streets, .05)) +  #large file, 5% used for example
  geom_sf(aes(color = POSTAL_R)) + 
  theme(legend.position = 'none')

Should get you here: enter image description here

Color palette needs to be adjusted, labels could be added, and geometries joined (or unioned) to get closer.

If you're really looking for a zip code map of Dallas, you should try to find a shapefile meant for that purpose.
A little closer:

dallas_streets %>% 
  sample_frac(.3) %>% 
  group_by(POSTAL_L) %>% 
  summarize(geometry = st_convex_hull(st_union(geometry))) %>% 
  ggplot() +
   geom_sf(aes(fill = as.numeric(POSTAL_L))) + 
   geom_sf_text(aes(label = POSTAL_L)) + 
   scale_fill_viridis_c(option = "C")

group_by, then summarize for a new geometry based on unioned convex hulls gets close to the actual zip code boundaries with only 30% of the data.

enter image description here

mrhellmann
  • 5,069
  • 11
  • 38
  • thanks, this works great. How would I be able to color in a single zipcode and leave the rest of the map greyscale? – memeium Dec 31 '19 at 18:33
  • @Marium I'm glad the solution worked so well. You may want to consider marking this question answered, and ask a new one to color a single zip code. https://stackoverflow.com/help/someone-answers – mrhellmann Dec 31 '19 at 18:48