Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Messy US county level map

    Hi, I tried to draw a US-county-level map by following online tutorials. However, I could not figure it out no matter how many times I tried. Can anyone please help me?
    I tried to upload shp file from the Census, but it was too large to upload. You can download the zip file from the attached website and use my stata code starting with spshape2dta.
    https://www.census.gov/geographies/m...tab-1556094155
    Attached Files
    Last edited by Coco Sun; 24 Apr 2024, 14:41.

  • #2
    You will usually want to apply the Albers projection to a map of the US because the country spans a wide range of latitudes and longitudes, resulting in significant distortions when projected onto a flat surface. Additionally, it's often preferable to map the continental United States separately. Note that spmap and geo2xy are from SSC.

    Code:
    copy https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_county_20m.zip uscounty.zip, replace
    unzipfile uscounty.zip, replace
    spshape2dta  cb_2018_us_county_20m, saving(uscounty) replace
    
    *APPLY ALBERS PROJECTION
    use uscounty_shp,clear
    geo2xy _Y _X, replace  proj(albers, 6378137 298.257223563 29.5 45.5 0 -95.837867)
    save , replace
    
    *REMOVE ALASKA, HAWAII & PUERTO RICO
    use uscounty.dta , clear
    drop if inlist(STATEFP, "02", "15", "72")
    gen x = 1  
     
    spmap x using uscounty_shp, id(_ID) ndsize(0.02 ..) ndocolor(black) osize(0.02 ..) fcolor(none) leg(off)
    Res.:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	308.7 KB
ID:	1751181

    Last edited by Andrew Musau; 24 Apr 2024, 15:36.

    Comment


    • #3
      Thank you Mr. Musau! I tried to apply your code, it worked. However, after I added polygon, it didn't work again. I want to have clear boundaries for each county.

      colorpalette HSV purplegreen, ipolate(5) nograph reverse
      local colors `r(p)'
      spmap availability20 using us_state_coordinates_20m_shp.dta, ///
      id(_ID) cln(5) fcolor("`colors'") ///
      legend(on) clbreaks(0 0.20 0.40 0.60 0.80 1.00) clmethod(custom) ///
      ocolor(gs6 ..) osize(0.03 ..) ///
      ndfcolor(gs14) ndocolor(gs6 ..) ndsize(0.03 ..) ndlabel("No data") ///
      polygon(data("us_state_coordinates_20m_shp") ocolor(black) osize(0.08) legenda(on) legl("Countries")) ///
      legend(label(2 "0.00 to 0.20") label(3 "0.20 to 0.40") label(4 "0.40 to 0.60" ) label(5 "0.60 to 0.80")label(6 "0.80 to 1.00") pos(11) size(1.5) symx(2.5) symy(1.5)) legtitle("Ratio") legstyle(2) ///
      note("Data source: European Commission Household Broadband Coverage. NUTS 2016 layers from Eurostat GISCO.", size(1.8))
      Attached Files

      Comment


      • #4
        I'm not sure how you want me to help you. With a dark green fill and county borders in black, you'll have a hard time identifying the border outlines. You should consider using transparency and lighter shades instead. Additionally, when including Alaska, Hawaii, and the island territories, you'll barely be able to see the smaller counties, primarily those along the East Coast.

        Comment

        Working...
        X