Announcement

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

  • spmap: Move legend position

    Hi

    I am using Stata 15.0. I am creating maps using spmap and want to move the position of the legend but don't see anything on this in the helpfile. I downloaded the shape maps files for South Africa and then adjusted the file to only include the perimeters of the map that I am interested in saving this as "nalcoord" and "naldb" (see below).

    The variable, temp, and the two coordinate variables are below (just for observations 1-8 for simplicity):
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float temp double(d14_longitude d14_latitude)
     1   29.76778   -31.01171
     2   29.76806    -31.0615
     3  29.776561  -29.051018
     6 30.2256401 -31.0056761
     8  30.194423  -30.962085
    16   29.89055    -31.0671
    19 30.8276417 -30.0593772
    25  29.132649  -28.688167
    end
    My code to create the map is below

    Code:
    * Save the specific local municipalities I am interested in
    use "$maps/rsadb_lm.dta", clear
    keep if OBJECTID==15|OBJECTID==161|OBJECTID==162|OBJECTID==163|OBJECTID==40|OBJECTID==39|OBJECTID==38|OBJECTID==152|OBJECTID==168|OBJECTID==43|OBJECTID==42|OBJECTID==41|OBJECTID==55
    save "$maps/naldb_lm.dta", replace
    list OBJECTID
    use "$maps/rsacoord_lm.dta", clear
    keep if _ID==15|(_ID>=38&_ID<=64)|(_ID>=152&_ID<=156)|(_ID>=161&_ID<=175)|(_ID>=206&_ID<=207)
    drop if _ID==164|_ID==165
    save "$maps/nalcoord_lm.dta", replace
    
    *Create the map
    spmap using "$maps/nalcoord_lm.dta", id(_ID) line(data("$maps/nalcoord_lm.dta") size(vvthin)) /*
    */ point(data("$temp\temp1.dta") by(n) fcolor(Blues2) ocolor(none) size(vtiny) xcoord(d14_long) ycoord(d14_lat) legenda(on) legtitle(Number RCs)) /*
    */label(data("$maps/naldb_lm.dta") xcoord(x_c) ycoord(y_c) label(OBJECTID) size(medium)) title(Number of RCs)
    My legend covers the map. How do I move the position of it - ideally to the top left corner?

    Thanks
    Megan

  • #2
    The position() and ring() legend sub-options override the default location of the legend. In particular the ring option greater than zero will place it outsize the plot region.
    Using the spmap ancillary datasets compare:

    Code:
    use "Italy-RegionsData.dta", clear
    spmap relig1 using "Italy-RegionsCoordinates.dta", id(id)          ///
        clnumber(20) fcolor(Greens2) ocolor(white ..) osize(medthin ..)    ///
        title("Pct. Catholics without reservations", size(*0.8))           ///
        subtitle("Italy, 1994-98" " ", size(*0.8))                       ///
         name(gr1,replace)
    
    spmap relig1 using "Italy-RegionsCoordinates.dta", id(id)          ///
        clnumber(20) fcolor(Greens2) ocolor(white ..) osize(medthin ..)    ///
        title("Pct. Catholics without reservations", size(*0.8))           ///
        subtitle("Italy, 1994-98" " ", size(*0.8))                       ///
        legend(pos(6) row(3) ring(1) size(*.75) symx(*.75) symy(*.75) forcesize ) /// 
        name(gr2,replace)

    Comment


    • #3
      Hi

      Thanks for your response. That method doesn't work with "point" though as far as I can see? I have used it when I have created heatmaps for particular municipalities, but when I want to create a map with points of different colours it says "legend" is not allowed.

      Best
      Megan

      Comment

      Working...
      X