Announcement

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

  • Trouble using ocolor() option in spmap to drop all polygon outlines

    I am trying to create a map at the U.S. census tract level. The borders of the polygon are currently obscuring the fill color in the most densely populated tracts, and I am trying to remove it. I am able to remove some of the outlines--but not all of them--using the ocolor(none) option. I did not start out with a dataset containing IDs that allowed it to be directly merged with a shapefile, but it does contain coordinates so that I could prepare the data for mapping by doing the following:
    Code:
    shp2dta using "tl_2018_06_tract.shp", ///
        database("cal_tract_db") ///
        coordinates("cal_tract_coord") ///
        genid(id) replace
    
    use "LA_exposure_SFD", clear
    geoinpoly latitude longitude using "cal_tract_coord"
    rename _ID id
    merge m:1 id using "cal_tract_db"
    drop if _merge == 2 | _merge == 1
    save "LA_exposure_SFD_tract", replace
    Once the shapefile ID has been merged into the main dataset, I then try to start mapping:

    Code:
    preserve 
    drop if county != "LOS ANGELES COUNTY"
    collapse (mean) probabilityofins (mean) limit (mean) deductible (mean)distancetowuiinterface ///
                  (mean) urbanconflagrationscore (mean) stochasticburnprob (mean) distancetocalfireveryhigh ///
                  (mean) distancetocalfirehigh (mean) distancetocalfiremedium (count) locname, by(id)
    
    * This is the map with all the polygon outlines left in place *
    spmap probabilityofins using "$datapath/Raw/California_shapefiles/california_tract/cal_tract_coord", ///
                                                   id(id) fcolor(Blues) clnumber(5)
    
    graph export "/work/sf/internal/l1werp20.sf.frb.org/shared/Stephanie/Climate Vendor Model Project/test_tract_graph_v1.png", ///
                                                  as(png) name("Graph") replace
    
    *This is the map where I have tried to remove the outlines.
    spmap probabilityofins using "$datapath/Raw/California_shapefiles/california_tract/cal_tract_coord", ///
                                                    id(id) fcolor(Blues) ocolor(none) clnumber(5)
    
    graph export "/work/sf/internal/l1werp20.sf.frb.org/shared/Stephanie/Climate Vendor Model Project/test_tract_graph_v2.png", ///
                                                    as(png) name("Graph") replace
    
    restore
    This is what the figure looks like without the ocolor(none) option specified, as I would expect.

    Click image for larger version

Name:	test_tract_graph_v1.png
Views:	1
Size:	132.9 KB
ID:	1698760






    This is what the figure looks like with the ocolor(none) option specified. I haven't added any additional layers to the map, so I am not sure why some of the outlines would disappear while others would still show up on the map.
    Click image for larger version

Name:	test_tract_graph.png
Views:	1
Size:	87.6 KB
ID:	1698761


    Thank you in advance!

  • #2
    spmap is from SSC (FAQ Advice #12). The outline color of the base map polygons can be specified using the option -ndocolor()-. Probably best to allow some visibility of the outline by controlling intensity, otherwise one will not be able to make out the underlying borders.

    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
    
    use uscounty_shp,clear
    geo2xy _Y _X, replace  proj(albers, 6378137 298.257223563 29.5 45.5 0 -95.837867)
    save , replace
    
    use uscounty.dta , clear
    drop if inlist(STATEFP, "02", "15", "72")
    gen x = 1  if runiform() < .05
     
    spmap x using uscounty_shp, id(_ID)  ndsize(0.02 ..) ndocolor(black*0.5)  osize(0.02 ..) ///
        fcolor("68 1 84")
    Res.:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	282.5 KB
ID:	1698780

    Last edited by Andrew Musau; 25 Jan 2023, 12:18.

    Comment


    • #3
      You need to apply the repeat element " .. " in the -ocolor(none ..) option so that it applies to all the categories, not just the first one. Also, your map appears to include a Census tract from Kern County.

      Code:
      copy https://www2.census.gov/geo/tiger/TIGER2022/TRACT/tl_2022_06_tract.zip ca_tract.zip, replace
      unzipfile ca_tract.zip, replace
      spshape2dta  tl_2022_06_tract, saving(ca_tract) replace
      
      use ca_tract,clear
      // LA County
      keep if COUNTY == "037"
      gen x = runiform()
      format x %9.3f
      
      //Drop Channel Islands
      spmap x using ca_tract_shp if  !inlist(NAME, "5990", "5991"), id(_ID) /// 
          fcolor(Blues)  ocolor(none ..) clnumber(5) 
      
      graph export "C:\Users\scott\Desktop\tmp\ca_tracts.png", as(png)  /// 
           width(800) height(600) name("Graph") replace
      Click image for larger version

Name:	ca_tracts.png
Views:	1
Size:	161.2 KB
ID:	1698806

      Comment

      Working...
      X