Announcement

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

  • Facing problem - mapping using spmap package

    Dear All,
    I am using STATA 14 to create a map using spmap package. I have a variable "club" which represents values from 1 to 6. I want a map showing six clubs in six different colors. The problem I am facing is - when I plot the variable it becomes 3 clubs in 3 colors. So stata is taking a range and making 3 clubs instead of 6. How can I solve it? I have attached an image of six maps showing the clubs but I want six clubs in one map.

    Here is the code I have used - spmap club using bdcoor, id(id) fcolor(Greys2) ///
    legenda(on) ///
    title("Upazilas from Club 6")

    Can anybody please guide me towards the solution?
    Attached Files

  • #2
    You wrote:
    the code I have used .... title("Upazilas from Club 6")
    I don't think that spmap would produce the 6 charts stitched together with different titles completely on it's own. So probably the code that you've typed is different from what you are showing. One way or another, I feel there is some contradiction in your description.

    Assuming that the maps are indeed what needs to be shown, and the only thing that you wish to adjust is the color of the highlight (e.g. first map in red, second in green, etc), then spmap has an option to control the palette, and rather than using Greys2 you can specify your own colors lists for each plot in fcolor().

    Comment


    • #3
      I have used the code to produce one map at a time then I have just combined all 6 maps. I can show six clubs on six different maps which I have already done. But I want to create one map showing six clubs in six colors.
      Can you please help me with the code for spmap package with which I will be able to create a map representing six clubs?

      Comment


      • #4
        Assuming you have 1 record per upazila with no duplicates, something like this should suffice:
        Code:
        // Generate some random data:
        clear all
        set obs 20
        generate id=_n
        generate club=int(runiform()*6+1)
        tabulate club
        
        // Plot the data on a map of Italy:
        spmap club using italy-regionscoordinates, id(id) clmethod(unique) ///
            fcolor(orange green red cyan yellow maroon) ///
            legend(title("Most popular club", size(small)) pos(2))

        Click image for larger version

Name:	clubs.png
Views:	1
Size:	95.9 KB
ID:	1591760




        Code:
               club |      Freq.     Percent        Cum.
        ------------+-----------------------------------
                  1 |          3       15.00       15.00
                  2 |          3       15.00       30.00
                  3 |          3       15.00       45.00
                  4 |          4       20.00       65.00
                  5 |          3       15.00       80.00
                  6 |          4       20.00      100.00
        ------------+-----------------------------------
              Total |         20      100.00
        For the randomly generated data (result will vary randomly):

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input float(id club)
         1 5
         2 6
         3 1
         4 2
         5 4
         6 3
         7 4
         8 2
         9 3
        10 1
        11 1
        12 2
        13 4
        14 6
        15 5
        16 6
        17 5
        18 4
        19 3
        20 6
        end

        Comment


        • #5
          Thank you so much. It worked!!
          I need another suggestion. I have attached the picture of my map. I have 573 upazilas under 8 divisions. I want to include just the division names in my map. I have used the following code -
          spmap club using bdcoor, id(id) clmethod(unique)fcolor(Set1) label(xcoord(x_c) ycoord(y_c) size(large) label( division)) legenda(on) title("Upazilas from Six Clubs", size(small))
          It works. But it gives 8 names for 573 times. How can I avoid this problem and keep only 8 names?
          Attached Files

          Comment


          • #6
            If I were to see the above map with 8 words corresponding to 8 divisions superimposed on top, I would have no idea where the boundaries of those divisions are. So the behavior of -spmap- is logical and understandable here.
            Get a map at the division level and overlay on top of the current map, spmap can do that. Naturally when you have 8 divisions in that layer, you will have 8 labels.

            Best, Sergiy Radyakin

            Comment


            • #7
              Dear Jobaida Behtarin and @Sergiy Radyakin,

              I hope you're well. I am really happy to see your useful discussion. I am quite new to -spmap- command in Stata and I hope you will help me to solve my problem. Thanks in Advance.

              I am using the following codes to present hot spots and cold spots of Low birth weight in Bangladesh.


              getisord LBW_yes, lat(LATNUM) lon(LONGNUM) swm(bin) dist(50) dunit(km) approx detail

              spmap go_z_LBW_yes_b using "nat-c", id(id) clm(custom) clb(-100 -2.576 -1.960 1.960 2.576 100) fcolor(ebblue eltblue white orange red) legtitle("{it: z}-value") legstyle(1) legcount legend(size(*1.8))


              I am using the 2017/18 Bangladesh Demographic and Health Survey data and their shapefile for the geographic coordinates. The codes used correctly produced the number of hot spots and cold spots, however, a problem arises when I am going to present results on the map. The Map takes an unusual shape than different, as represented below-


              Click image for larger version

Name:	Graph1.jpg
Views:	1
Size:	634.9 KB
ID:	1610230







              Comment

              Working...
              X