Announcement

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

  • Polygons hidden behind others when creating choropleth map using spmap

    Hi everyone - this is my first ever post on this forum.

    I've been having a problem using the spmap command. I'm plotting proportions of antibiotic-resistant isolates by region. I also have the data split up by community and hospital isolates. In order to compare the proportion resistant from community isolates with hospital isolates within a particular region I created artificial circular "regions" to represent the hospitals - it seems to me this was the only way to do it since there isn't an option in spmap to insert points/markers on a map and have them display the data using the same (color) scale for both the community and hospital isolates. The problem is that some of these circles become either completely or partially hidden under the base map.

    Here is the code I used:

    Code:
       
    levelsof abx_class, local(abx)
        *E. coli
            foreach a of local abx {
                #delimit ;
                spmap percent_resistant
                    if organism == "E.coli" & abx_class == "`a'"
                    using coordinates_XY.dta, id(_ID)
                    title("`a'", size(small))
                    clbreaks(0(10)100) clmethod(custom) fcolor(Reds2) ndfcolor(white) ndlab("no isolates")
                    legtitle("% resistant") legstyle(2)
                    graphregion(color(white) margin(b=0 t=0)) plotregion(margin(b=0 t=0)) bgcolor(white)
                    name("`a'", replace)
                ;
                #delimit cr
            }
            grc1leg ESBLs Fluoroquinolones Gentamicin SXT, col(2) graphregion(color(white) margin(b=0 t=0)) title("{it:E. coli}", size(medsmall)) position(9) name(Ecoli, replace)
    Here are the data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str3 jurisdiction str36 region str48 organism str33 abx_class double(num_of_tests resistant susceptible) float percent_resistant long _ID
    "FNQ" "Mackay"                "E.coli" "ESBLs"               .   .    .         .       1
    "FNQ" "Mackay"                "E.coli" "Fluoroquinolones"    .   .    .         .       1
    "FNQ" "Mackay"                "E.coli" "Gentamicin"          .   .    .         .       1
    "FNQ" "Mackay"                "E.coli" "SXT"                 .   .    .         .       1
    "FNQ" "Townsville"            "E.coli" "SXT"                 .   .    .         .       2
    "FNQ" "Townsville"            "E.coli" "Gentamicin"          .   .    .         .       2
    "FNQ" "Townsville"            "E.coli" "ESBLs"               .   .    .         .       2
    "FNQ" "Townsville"            "E.coli" "Fluoroquinolones"    .   .    .         .       2
    "FNQ" "North West"            "E.coli" "SXT"                 .   .    .         .       3
    "FNQ" "North West"            "E.coli" "Gentamicin"          .   .    .         .       3
    "FNQ" "North West"            "E.coli" "ESBLs"               .   .    .         .       3
    "FNQ" "North West"            "E.coli" "Fluoroquinolones"    .   .    .         .       3
    "FNQ" "Cairns and Hinterland" "E.coli" "SXT"                 .   .    .         .       4
    "FNQ" "Cairns and Hinterland" "E.coli" "Gentamicin"         15   0   15         0       4
    "FNQ" "Cairns and Hinterland" "E.coli" "ESBLs"              10   0   10         0       4
    "FNQ" "Cairns and Hinterland" "E.coli" "Fluoroquinolones"   10   0   10         0       4
    "FNQ" "Torres and Cape"       "E.coli" "Fluoroquinolones"    .   .    .         .       5
    "FNQ" "Torres and Cape"       "E.coli" "Gentamicin"          .   .    .         .       5
    "FNQ" "Torres and Cape"       "E.coli" "ESBLs"               .   .    .         .       5
    "FNQ" "Torres and Cape"       "E.coli" "SXT"                 .   .    .         .       5
    "WA"  "Kimberley"             "E.coli" "Fluoroquinolones"   55   7   48 12.727273     304
    "WA"  "Kimberley"             "E.coli" "SXT"                 9   5    4  55.55556     304
    "WA"  "Kimberley"             "E.coli" "Gentamicin"         13   3   10 23.076923     304
    "WA"  "Kimberley"             "E.coli" "ESBLs"               9   5    4  55.55556     304
    "NT"  "Alice Springs"         "E.coli" "Fluoroquinolones"  523  67  456 12.810707     334
    "NT"  "Alice Springs"         "E.coli" "SXT"               123  61   62  49.59349     334
    "NT"  "Alice Springs"         "E.coli" "ESBLs"             123  40   83 32.520325     334
    "NT"  "Alice Springs"         "E.coli" "Gentamicin"        506  61  445 12.055336     334
    "NT"  "Barkly"                "E.coli" "Fluoroquinolones"  745  92  653 12.348993     335
    "NT"  "Barkly"                "E.coli" "SXT"               212 106  106        50     335
    "NT"  "Barkly"                "E.coli" "Gentamicin"        724 106  618 14.640884     335
    "NT"  "Barkly"                "E.coli" "ESBLs"             213  56  157  26.29108     335
    "NT"  "East Arnhem"           "E.coli" "Fluoroquinolones"  206  12  194  5.825243     337
    "NT"  "East Arnhem"           "E.coli" "SXT"                36  24   12 66.666664     337
    "NT"  "East Arnhem"           "E.coli" "ESBLs"              36  11   25 30.555555     337
    "NT"  "East Arnhem"           "E.coli" "Gentamicin"        197  27  170 13.705584     337
    "NT"  "Katherine"             "E.coli" "Gentamicin"       1375  94 1281  6.836364     338
    "NT"  "Katherine"             "E.coli" "SXT"               315 162  153  51.42857     338
    "NT"  "Katherine"             "E.coli" "Fluoroquinolones" 1429  88 1341  6.158153     338
    "NT"  "Katherine"             "E.coli" "ESBLs"             316  61  255 19.303797     338
    "WA"  "Pilbara"               "E.coli" "Gentamicin"         47   3   44  6.382979   99999
    "WA"  "Pilbara"               "E.coli" "ESBLs"              44  12   32  27.27273   99999
    "WA"  "Pilbara"               "E.coli" "SXT"                44  21   23  47.72727   99999
    "WA"  "Pilbara"               "E.coli" "Fluoroquinolones"  281  21  260   7.47331   99999
    "NT"  "Darwin"                "E.coli" "SXT"               323 155  168  47.98762  999999
    "NT"  "Darwin"                "E.coli" "Fluoroquinolones" 1856 147 1709  7.920259  999999
    "NT"  "Darwin"                "E.coli" "ESBLs"             323 105  218  32.50774  999999
    "NT"  "Darwin"                "E.coli" "Gentamicin"       1719 110 1609  6.399069  999999
    "NT"  "Darwin_hospital"       "E.coli" "Gentamicin"       1172 109 1063  9.300342 9000000
    "NT"  "Darwin_hospital"       "E.coli" "SXT"              1169 393  776 33.618477 9000000
    "NT"  "Darwin_hospital"       "E.coli" "ESBLs"            1172 118 1054  10.06826 9000000
    "NT"  "Darwin_hospital"       "E.coli" "Fluoroquinolones" 1172 130 1042  11.09215 9000000
    "NT"  "Gove_hospital"         "E.coli" "Gentamicin"        127  20  107 15.748032 9000001
    "NT"  "Gove_hospital"         "E.coli" "Fluoroquinolones"  127  10  117  7.874016 9000001
    "NT"  "Gove_hospital"         "E.coli" "SXT"               127  48   79 37.795277 9000001
    "NT"  "Gove_hospital"         "E.coli" "ESBLs"             127  10  117  7.874016 9000001
    "NT"  "Tennant_hospital"      "E.coli" "ESBLs"             131   9  122  6.870229 9000002
    "NT"  "Tennant_hospital"      "E.coli" "SXT"               130  53   77  40.76923 9000002
    "NT"  "Tennant_hospital"      "E.coli" "Gentamicin"        131  18  113 13.740458 9000002
    "NT"  "Tennant_hospital"      "E.coli" "Fluoroquinolones"  131  18  113 13.740458 9000002
    "NT"  "Katherine_hospital"    "E.coli" "SXT"                37  13   24 35.135136 9000003
    "NT"  "Katherine_hospital"    "E.coli" "Fluoroquinolones"   37   1   36  2.702703 9000003
    "NT"  "Katherine_hospital"    "E.coli" "ESBLs"              37   2   35  5.405406 9000003
    "NT"  "Katherine_hospital"    "E.coli" "Gentamicin"         37   3   34 8.1081085 9000003
    "NT"  "Alice_hospital"        "E.coli" "Fluoroquinolones"   67  14   53 20.895523 9000004
    "NT"  "Alice_hospital"        "E.coli" "Gentamicin"         67  11   56  16.41791 9000004
    "NT"  "Alice_hospital"        "E.coli" "SXT"                67  33   34  49.25373 9000004
    "NT"  "Alice_hospital"        "E.coli" "ESBLs"              67   8   59 11.940298 9000004
    "FNQ" "Cairns_hospital"       "E.coli" "Fluoroquinolones" 1721 125 1596  7.263219 9000007
    "FNQ" "Cairns_hospital"       "E.coli" "Gentamicin"       2082  93 1989  4.466859 9000007
    "FNQ" "Cairns_hospital"       "E.coli" "ESBLs"            1720  35 1685 2.0348837 9000007
    end
    I've attached the corresponding coordinates .dta file. coordinates_XY.dta

    Any help much appreciated.

    Will



  • #2
    I think the problem is that percent variable for the circles is not different enough from the regions they located in.

    Code:
    keep if abx == "ESBLs"
    replace percent = runiform(60 ,100) in 13/18
    spmap percent_resistant using  coordinates_xy.dta    , /// 
        id(_ID)  clbreaks(0(10)100) clmethod(custom) fcolor(Reds2)     /// 
        legend(pos(11))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	102.3 KB
ID:	1568614



    You could also do something like:
    Code:
    keep if abx == "ESBLs"
    //replace percent = runiform(60 ,100) in 13/18
    spmap percent_resistant using  coordinates_xy.dta    , /// 
        id(_ID)  clbreaks(0(10)100) clmethod(custom) fcolor(Reds2)     /// 
        legend(pos(11)) polygon(data(coordinates_xy) select(keep if _ID>=9000000  ) /// 
        ocolor(black) )
    Click image for larger version

Name:	Graph2.png
Views:	1
Size:	108.8 KB
ID:	1568615

    Comment


    • #3
      Hi Scott - thanks very much for your suggestions.

      Your first approach made me realize that if the circle has a percent_resistant value equal to or lower than the region's value (not the exact value, just in terms of what bracket they're in), then it will be hidden behind. That's why when you replaced the circles' values as all above 60% they all appear.

      Haven't thought about how to get around this yet, but great to be able decipher what's going on!

      Cheers,

      Will

      Comment


      • #4
        Hello again.

        After contacting the author of -spmap- I was advised that I need to specify variable _EMBEDDED in the basemap dataset. Details in the -spmap- help file (Spatial data format).

        This approach worked perfectly - thanks to Maurizio Pisati!

        Will

        Comment


        • #5
          I have exactly this problem so it was nice to see a solution. However, I wonder if there is a way to easily create the variable _EMBEDDED? I use shp2dta and I can't find an option.

          Comment

          Working...
          X