Announcement

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

  • Add Plot without Overwriting Existing Legends

    Hi All,

    I'm using add plot in combination with spmap. Addplot overwrites the spmap legend. Is it possible to use it WITHOUT overwriting the existing legend?

    Thanks

  • #2
    probably not.
    Perhaps you should look into Asjad Naqvi blog. He has many tutorials on how to customize Maps.
    One of those maybe what you need/want

    Comment


    • #3
      What kind of info do you want to add with addplot in spmap? Maybe there is already some way to incorporate this in the spmap command. Otherwise look at this guide: Stata graphs: Reprogramming maps which essentially gives full flexibility over how maps are made and drawn.

      Comment


      • #4
        Thanks a lot, Asjad! What I would like to do is having two legend: one for the color I'm giving to US states and another one for the points that I draw over the states. I would like the two to be separate. I've tried this code here:

        spmap census_district using "~$path/uscoord.dta", id(id) ///
        clmethod(unique) fcolor(gs6 "255 237 111" "191 211 230" "254 232 200" "188 128 189" "217 217 217" "252 205 229" "128 177 211" "190 186 218" "255 255 179" "141 211 199" "166 206 227" "251 154 153" "253 191 111" "202 178 214" "246 232 195" "199 234 229" "241 182 218" "230 245 152") ///
        ocolor(none ..) legend(ring(5) pos(9) size(*1.8) symx(*.85) symy(*.85) row(3) col(3)) ///
        point(data("~path/firms.dta") by(indicator) xc(lng) yc(lat) size(small small) shape(X Th) fcolor(red black) legenda(off))

        addplot: (scatter census_district nodata1, msize(*1.5) mcolor(red) msymbol(Th)) || (scatter census_district nodata2 , msize(*1.5) mcolor("0 63 92") msymbol(X) norescaling))

        but add plot overwrites the first legend that I need.

        Thanks a lot!

        Comment


        • #5
          Joshua Smith​​ ​sorry for the slow response! I am not here often.

          You can achieve what you want from spmap without requiring addplot.

          See this example below:


          Code:
          spmap y_TOT using nuts3_shp if CNTR_CODE=="FR", ///
              id(_ID) cln(6) fcolor("`colors'") ///
              ocolor(gs12 ..) osize(0.1 ..)   ///
                  legend(pos(7) size(1.8)) legstyle(2) legtitle("Population (Per. Nr.)")    ///
                  polygon(data("nuts0_shp") select(keep if CNTR_CODE=="FR") ocolor(navy) osize(0.1) legenda(off) )     ///
                  point(data("places_proj") select(keep if population>50000) by(popcut) x(_CX) y(_CY) proportional(population) psize(absolute) fcolor(orange%60 lime%60) ocolor(white black) osize(vthin vthin) size(1.3) legenda(on) )  ///
                  line( data("roads_shp_proj") select(keep if layer==2) color(black) size(0.1) pattern(solid) )  ///
                      title("{fontface Merriweather Bold:France regions, major cities, and highways}", size(3.5)) ///
                      note("Source: Open Street Maps. Cities with population > 200,000 are labeled.", size(1.5))

          Click image for larger version

Name:	maps_splitpoints.png
Views:	1
Size:	784.3 KB
ID:	1664969



          Here we use "by" to split the points into categories. The underlying points file "places_proj" needs to have the category variable ("popcut" in the example above), with the cuts and the value labels defined. spmap can pick this information and plot it.

          Hope this helps!
          Last edited by Asjad Naqvi; 17 May 2022, 02:30.

          Comment

          Working...
          X