Announcement

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

  • Problems with the command spmap

    Hello everyone,

    I have two problems with the spmap command and I need your help.
    I am making a map for the provinces of Ecuador where I put the name of each province but in some provinces the name comes out and I would like to know if there is any way to put those names in two lines. On the other hand, I would like to know if there is a way to put the province of Azuay with a different color, for example gray.

    spmap descronica_2 using prov_shp, id(_ID) clmethod(custom) clbreaks(19(2.85)42) fcolor(PuRd) osize(*0.15 ..) ndocolor(black) ndfcolor(gs14) ndlabel("No data") ndsize(*0.15 ..) legend(pos(7) size(*1.2)) ///
    legend(label(2 "19% - 22%") label(3 "22% - 25%") label(4 "25% - 28%" ) label(5 "28% - 30%" ) label(6 "30% - 33%" ) label(7 "33% - 36%" ) label(8 "36% - 39%") label (9 "39% - 42%")) ///
    legstyle(2) label(data("prov.dta") xcoord(_CX) ycoord(_CY) label(DPA_DESPRO) size(*0.50 ..) length(16)) legend(subtitle("Prevalencia", bexpand justification(center) size(small)))
    Click image for larger version

Name:	grafico.PNG
Views:	3
Size:	119.1 KB
ID:	1679787

    Thanks.
    Attached Files

  • #2
    spmap is from SSC (FAQ Advice #12). Look at the _ID corresponding to Azuay and keep just this. Then use the -polygon()- option, embedded to your existing code.


    Assuming it is _ID=7 below:

    Code:
    preserve
    keep if _ID==7
    save "Azuay", replace
    restore
    spmap ... polygon(data("Azuay.dta") fcolor(gray))

    Comment


    • #3
      See the following code, for which I've used the ancillary datasets provided with -spmap- (command available from SSC; datasets available by doing -net get spmap-). Labels with multiple words have been split into two lines. I've highlighted the region called "Toscana" in grey. I've retained as much of the code from your original command as I could.

      Code:
      use italy-regionsdata, clear
      
      clonevar reglabel = region
      split reglabel if length(reglabel) > 12
      replace reglabel1 = reglabel if missing(reglabel1)
      
      drop reglabel
      reshape long reglabel , i(id xcoord ycoord) j(num)
      drop if missing(reglabel)
      
      save reglabels, replace
      
      use italy-regionsdata, clear
      
      sum id if region == "Toscana"
      local wanted = r(mean)
       
      #delimit ;
      spmap relig2 using italy-regionscoordinates,
              label(data(reglabels.dta) x(xcoord) y(ycoord) label(reglabel) by(num) pos(0 6) size(*0.50 ..) length(16))
              polygon(data( "italy-regionscoordinates.dta") select(keep if _ID == `wanted') fcolor(gs10))
              id(id)
              clmethod(custom) clbreaks(19(2.85)42) fcolor(PuRd) osize(*0.15 ..)
              ndocolor(black) ndfcolor(gs14) ndlabel("No data") ndsize(*0.15 ..)
              legend(pos(7) size(*1.2))
              legend(    label(2 "19% - 22%")
                      label(3 "22% - 25%")
                      label(4 "25% - 28%" )
                      label(5 "28% - 30%" )
                      label(6 "30% - 33%" )
                      label(7 "33% - 36%" )
                      label(8 "36% - 39%")
                      label(9 "39% - 42%"))
              legstyle(2)
              legend(subtitle("Prevalencia", bexpand justification(center) size(small)))
              ;
      #delimit cr
      which produces:
      Click image for larger version

Name:	Screenshot 2022-08-30 at 1.14.24 AM.png
Views:	1
Size:	228.4 KB
ID:	1679794

      Last edited by Hemanshu Kumar; 29 Aug 2022, 13:54.

      Comment


      • #4
        Thank you very much Andrew Musau and Hemanshu Kumar helped me a lot

        Comment


        • #5
          Another query is it possible to put the name of two provinces with different colors, that is, in my graph I want to put the name Chimborazo in white but I don't know how.

          Comment


          • #6
            The trick is to create another group of labels and give it its own properties in the label() sub-options.

            Code:
            use italy-regionsdata, clear
            
            sum id if region == "Toscana"
            local wanted = r(mean)
            
            clonevar reglabel = region
            split reglabel if length(reglabel) > 12
            replace reglabel1 = reglabel if missing(reglabel1)
            
            drop reglabel
            
            reshape long reglabel , i(id xcoord ycoord) j(num)
            replace num = 3 if reglabel == "Veneto"
            drop if missing(reglabel)
            
            save reglabels, replace
            
            use italy-regionsdata, clear
            
             
            #delimit ;
            spmap relig2 using italy-regionscoordinates,
                    label(data(reglabels.dta) x(xcoord) y(ycoord) label(reglabel) by(num) pos(0 6 0) size(*0.50 ..) length(16) color(black black white))
                    polygon(data( "italy-regionscoordinates.dta") select(keep if _ID == `wanted') fcolor(gs10))
                    id(id)
                    clmethod(custom) clbreaks(19(2.85)42) fcolor(PuRd) osize(*0.15 ..)
                    ndocolor(black) ndfcolor(gs14) ndlabel("No data") ndsize(*0.15 ..)
                    legend(pos(7) size(*1.2))
                    legend(    label(2 "19% - 22%")
                            label(3 "22% - 25%")
                            label(4 "25% - 28%" )
                            label(5 "28% - 30%" )
                            label(6 "30% - 33%" )
                            label(7 "33% - 36%" )
                            label(8 "36% - 39%")
                            label(9 "39% - 42%"))
                    legstyle(2)
                    legend(subtitle("Prevalencia", bexpand justification(center) size(small)))
                    ;
            #delimit cr
            This produces:
            Click image for larger version

Name:	Screenshot 2022-08-30 at 3.43.15 AM.png
Views:	1
Size:	228.2 KB
ID:	1679804

            Last edited by Hemanshu Kumar; 29 Aug 2022, 16:23.

            Comment


            • #7
              Thank you very much for your help.
              Another query is it possible to put the name of two provinces with different colors, that is, in my graph I want to put the name Chimborazo in white but I don't know how.

              Comment


              • #8
                Please see my post #6 above.

                Comment


                • #9
                  Thank you for your help and in case you want to put only the province of Santa Elena, which is in two lines, how do I do it because I was trying and it did not work
                  Attached Files

                  Comment


                  • #10
                    Based on #1 (everything is in one line to begin with)

                    label(data("prov.dta") xcoord(_CX) ycoord(_CY) label(DPA_DESPRO) size(*0.50 ..) length(16))
                    You can add the modification:

                    Code:
                    use prov.dta, clear
                    replace DPA_DESPRO= "Santa`=char(13)'`=char(10)'Elena" if DPA_DESPRO= "Santa Elena"
                    save, replace
                    and then proceed as before.
                    Last edited by Andrew Musau; 30 Aug 2022, 08:59.

                    Comment


                    • #11
                      Thank you for your help

                      Comment

                      Working...
                      X