Announcement

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

  • Legend problem using spmap

    I am creating several maps showing hospitals using the spmap command in Stata 12. I have a problem related to the legend. Each hospital gets a score, A-E, (the variable Pd1_n in my code example) and the associated marker is assigned a colour. I am creating these maps for several different scoring variables and regions I want the legend to look the same in all maps (eg. “A” should always be green and “C” always orange). My problem is that for some regions not all scores will be represented in the data set and when this happens the legend changes. For example, if there is no hospital with a “B” score then my legend will show “C” scores in dark green instead of orange and the labels will no longer be correct (“C”s will look like “B”s). Is there a way of making sure that the legend always looks a certain way (always shows A-E with the right colours)?

    Here is a simplified example of my code.

    use scndta, clear
    spmap using scncoor, id(id) ///
    legend(on label(3 "A (90+)") label(4 "B (80-99)") label(5 "C (75-79)") label(6 "D (65-74)") label(7 "E<65") label(8 "Insufficient records") order(3 4 5 6 7 8 )) ///
    point(data("merged_hospitals.dta") x(Easting) y(Northing) ") by(Pd1_n) ///
    fcolor(green dkgreen orange dkorange cranberry black) shape(O D O S T X) size(small))

    At the moment the only way I can think of to solve this problem is to add fake data with all scores to the data set I use in the point option (merged_hospitals) and give my fake data points coordinates that will be hidden behind the legend but this is really time consuming. Is there a better way of doing it?

  • #2
    Emma, in amap you can control whether to display the legend color keys for empty categories, not sure about a similar option in spmap. Adding fake data doesn't look like a good idea. You can probably render all maps without a legend, then render the legend separately (and not necessarily with spmap) and combine everything together into a single infographic. Using google maps might be a better solution here. Best, Sergiy Radyakin

    Comment


    • #3
      Thank you. I will try amap.

      Emma

      Comment


      • #4
        You can have empty categories in the legend using the clmethod(custom) option.


        Code:
         use "Italy-RegionsData.dta", clear
        
         spmap relig1 using "Italy-RegionsCoordinates.dta", id(id) clmethod(custom) clbreaks(0 10 20 30 40 50 60 70 80 90 100) legcount  fcolor(Greys2)

        Comment

        Working...
        X