Announcement

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

  • Maptile error with legend

    Dear All,
    I am trying to make a policy map using maptile and am having some issues with creating the correct legend. Here is my data:

    [CODE]
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte statefips str15 pol1 float pol2
     2 "June 1, 2023"    3
     1 "June 1, 2023"    3
     5 "April 1, 2023"   1
     4 "April 1, 2023"   1
     6 "July 1, 2023"    4
     8 "June 1, 2023"    3
     9 "May 1, 2023"     2
    11 "June 1, 2023"    3
    10 "July 1, 2023"    4
    12 "May 1, 2023"     2
    13 "June 1, 2023"    3
    15 "June 1, 2023"    3
    19 "May 1, 2023"     2
    16 "April 1, 2023"   1
    17 "July 1, 2023"    4
    18 "May 1, 2023"     2
    20 "May 1, 2023"     2
    21 "June 1, 2023"    3
    22 "July 1, 2023"    4
    25 "June 1, 2023"    3
    24 "June 1, 2023"    3
    23 "June 1, 2023"    3
    26 "July 1, 2023"    4
    27 "July 1, 2023"    4
    29 "Excluded"        6
    28 "June 1, 2023"    3
    30 "June 1, 2023"    3
    37 "July 1, 2023"    4
    38 "June 1, 2023"    3
    31 "Excluded"        6
    33 "April 1, 2023"   1
    34 "June 1, 2023"    3
    35 "May 1, 2023"     2
    32 "June 1, 2023"    3
    36 "July 1, 2023"    4
    39 "May 1, 2023"     2
    40 "Excluded"        6
    41 "October 1, 2023" 5
    42 "May 1, 2023"     2
    44 "June 1, 2023"    3
    45 "June 1, 2023"    3
    46 "Excluded"        6
    47 "June 1, 2023"    3
    48 "June 1, 2023"    3
    49 "May 1, 2023"     2
    51 "May 1, 2023"     2
    50 "June 1, 2023"    3
    53 "June 1, 2023"    3
    55 "June 1, 2023"    3
    54 "May 1, 2023"     2
    56 "May 1, 2023"     2
    end
    Here is my maptile code:

    Code:
    . maptile pol2, geo(state) geoid(statefips) fcolor(navy midblue ebblue emerald eltgreen gray) twopt(legend(lab( 1 "April 1, 2
    > 023") lab(2 "May 1, 2023") lab(3 "June 1, 2023") lab(4 "July 1, 2023") lab(5 "October 1, 2023") lab(6 "Excluded")) legend(c
    > ol(1) )) cutp(pol2)
    Graph.gph
    3 things are not correct in the legend:
    (1) The order of the legend is reversed i.e. Excluded, October, July, June, May and April instead of April, May, June, July, October and Excluded.
    (2) April 1, 2023, label value is missing even though it's specified in legend (lab) option
    (3) 2 additional legend values 5-6 and 6-6 have been added.

    I am not sure what I am doing wrong and have played around quite a bit with the legend option but cannot figure this out. Would be very grateful for any help I can get.

    Many thanks in advance for your help. Gratefully,
    Sumedha

  • #2
    maptile is from SSC, as you are asked to explain in FAQ Advice #12. Use the -order()- suboption of -legend()- instead. Below, I order the legend according to the order specified within -fcolor()-.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte statefips str15 pol1 float pol2
     2 "June 1, 2023"    3
     1 "June 1, 2023"    3
     5 "April 1, 2023"   1
     4 "April 1, 2023"   1
     6 "July 1, 2023"    4
     8 "June 1, 2023"    3
     9 "May 1, 2023"     2
    11 "June 1, 2023"    3
    10 "July 1, 2023"    4
    12 "May 1, 2023"     2
    13 "June 1, 2023"    3
    15 "June 1, 2023"    3
    19 "May 1, 2023"     2
    16 "April 1, 2023"   1
    17 "July 1, 2023"    4
    18 "May 1, 2023"     2
    20 "May 1, 2023"     2
    21 "June 1, 2023"    3
    22 "July 1, 2023"    4
    25 "June 1, 2023"    3
    24 "June 1, 2023"    3
    23 "June 1, 2023"    3
    26 "July 1, 2023"    4
    27 "July 1, 2023"    4
    29 "Excluded"        6
    28 "June 1, 2023"    3
    30 "June 1, 2023"    3
    37 "July 1, 2023"    4
    38 "June 1, 2023"    3
    31 "Excluded"        6
    33 "April 1, 2023"   1
    34 "June 1, 2023"    3
    35 "May 1, 2023"     2
    32 "June 1, 2023"    3
    36 "July 1, 2023"    4
    39 "May 1, 2023"     2
    40 "Excluded"        6
    41 "October 1, 2023" 5
    42 "May 1, 2023"     2
    44 "June 1, 2023"    3
    45 "June 1, 2023"    3
    46 "Excluded"        6
    47 "June 1, 2023"    3
    48 "June 1, 2023"    3
    49 "May 1, 2023"     2
    51 "May 1, 2023"     2
    50 "June 1, 2023"    3
    53 "June 1, 2023"    3
    55 "June 1, 2023"    3
    54 "May 1, 2023"     2
    56 "May 1, 2023"     2
    end
    
    *maptile_install using "http://files.michaelstepner.com/geo_state.zip"
    maptile pol2, geo(state) geoid(statefips) fcolor(navy midblue ebblue emerald eltgreen gray) ///
    twopt(legend(order( 2 "April 1, 2023"  3 "May 1, 2023" 4 "June 1, 2023" 5 "July 1, 2023" 6 "October 1, 2023" 1 "Excluded")) ///
    legend(col(1) )) cutp(pol2)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	90.6 KB
ID:	1758189

    Last edited by Andrew Musau; 08 Jul 2024, 21:35.

    Comment


    • #3
      Dear Dr. Musau,
      I sincerely apologize for the delay in my response. Shortly after posting, a colleague suggested a similar solution, and I didn’t see your reply until recently. I’m very grateful for your time and help—thank you so much for your guidance.

      Warm regards,
      Sumedha

      Comment

      Working...
      X