Announcement

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

  • legend label in grmap plot

    Dear All,

    I use the following command

    Code:
    grmap msp_res1_yp9500, fcolor(blue blue*0.2 red*0.2 red) clmethod(custom) clb(0 1 2 3 4)
    to generate the following plot
    Click image for larger version

Name:	abc.png
Views:	1
Size:	274.9 KB
ID:	1712701




    I would like to change the legend. Specifically, I would like to have something like this:
    Click image for larger version

Name:	abd.png
Views:	1
Size:	273.6 KB
ID:	1712702




    More specifically, I would lile also to eliminate the last entry (No data).

    I tried to use the following:

    Code:
    grmap msp_res1_yp9500, fcolor(blue blue*0.2 red*0.2 red) clmethod(custom) clb(0 1 2 3 4) leglabl(High-High High-low Low-High Low-Low) legend(on)
    However, I get an error message saying that laglabl is not allowed. Of course I can modify the entries manually, but since I need to run several plots, it would be useful to be able to do this autonomtically.

    Any hint?

    FYI, the variable msp_res1_yp9500 takes only four values from 1 to 4 and it is labelled as Low Low; Low High; High Low and High High, respectively. The other entries which correspond to the white color in the map are missing.

    I use Stata 17 MP-4.

    Thanks in advance,

    Dario
    Last edited by Dario Maimone Ansaldo Patti; 08 May 2023, 05:20.

  • #2
    The option is -leglabel()- not -leglabl()-.

    Comment


    • #3
      Andrew Musau Thanks for spotting the mistake. Indeed I tried using the correct option but nothing changed. Below the graph I generated using leglabel()
      Click image for larger version

Name:	abde.png
Views:	1
Size:	270.0 KB
ID:	1712757


      As you can see the legend remains unaffected.

      Comment


      • #4
        I think you need the -order()- suboption within -legend()-.

        Code:
        legend(order( 1 "High-High" 2 "High-low" 3 "Low-High" 4 "Low-Low"))

        Comment


        • #5
          Andrew Musau thanks it worked. I am still in doubt about how to cancel the last entry (no data) but it is still fine what I got thanks to your suggestion

          Comment


          • #6
            I think #4 excludes that, the following includes it:

            Code:
            legend(order( 1 "High-High" 2 "High-low" 3 "Low-High" 4 "Low-Low" 5 "No data"))

            Comment


            • #7
              Andrew Musau yes you are right. The problem is that if i do not write 5 "No data" for whatsoever reason the colors are mixed up. I would like a specific color for each entry. If I do not include 5 "No data" for instance what is red in the previous map comes out as red*0.2

              Comment


              • #8
                I would need to see a reproducible example. Omitting a key in the legend should not affect anything.

                Comment


                • #9
                  Andrew Musau Solved. You were right: omitting a key in the legend does not modify anything....unless the command is not correctly specified, which was my case. The command I am using now is:

                  Code:
                  grmap msp_res1_`v', fcolor(blue blue*0.2 red*0.2 red) clmethod(custom) clb(0 1 2 3 4) legend(order( 5 "High-High" 4 "High-low" 3 "Low-High" 2 "Low-Low"))
                  Thanks for your help.

                  Comment

                  Working...
                  X