Announcement

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

  • Legend in graph combine

    Hello everybody.

    I use the next code to create bar graph:
    Code:
        twoway ///
            (bar mean_disqualified x if category_lbl == 1, barwidth(0.25) color(blue) lcolor(black)) ///
            (bar mean_disqualified x if category_lbl == 2, barwidth(0.25) color(gs12) lcolor(black)) ///
            (bar mean_disqualified x if category_lbl == 3, barwidth(0.25) color(red) lcolor(black)) ///
            (rcap lower_ci upper_ci x, lcolor(black)), ///
            xlabel(1 "Above Median" 2 "Below Median", labsize(small)) ///
            xscale(range(0.5 2.5)) ///
            ylabel(, angle(horizontal)) ///
            xtitle("") ///
            title("Measure 1", size(medium)) ///
            legend(order(1 "Upward Ethical Violation" 2 "Unbiased Teacher" 3 "Downward Ethical Violation") ///
            pos(6) row(1) size(vsmall)) ///
            name(g1, replace) ///
    And then I repeated it three additional time with three other measures, and I named the graphs g2, g3 and g4.

    Then, I wanted to combine all four graphs, to present them together, so I commanded Stata:

    Code:
    graph combine g1 g2 g3 g4, row(2) title("Figure 2") subtitle("Proportion of Disqualified Exams by Medians of Homogeneity Measures", size(medsmall)) iscale(.8) imargin(2 2 2 2) ycommon ///
    note("Upward ethical violation represents teachers with a positive difference of 10 points or higher, Downward ethical violation represents teachers with a negative difference of 10 points" ///
    "or lower, Unbiased teacher represents teachers who are neither upward nor downward ethical violators. 95% confidence intervals presented.", size(vsmall))
    The trouble is that the legend appear under every one of the four graphs in the combine figure. As far as I understand, you can't create legend with the command
    Code:
    graph combine
    , so I left legends only in the two lowers graphs in the combined figures, but it still looks a little bit stupid that the same legend appears twice.

    Can anybody help me and tell me how can I command Stata to put only one legend under the four combined graphs (and that it will be centered, of curse)

    Best,

    Fitzgerald

  • #2
    Check out the community-contributed command grc1leg2, which you can obtain from
    Code:
    net install grc1leg2.pkg

    Comment


    • #3
      Originally posted by Hemanshu Kumar View Post
      Check out the community-contributed command grc1leg2, which you can obtain from
      Code:
      net install grc1leg2.pkg
      Hi, thank you.

      I did this but Stata replied:

      Click image for larger version

Name:	11.png
Views:	1
Size:	6.1 KB
ID:	1780994


      Do know to explain me what to do?

      Thanks again,

      Fitz

      Comment


      • #4
        Package name is grc1leg2 i.e. letter g letter r letter c numeral 1 letter l and so on.

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Package name is grc1leg2 i.e. letter g letter r letter c numeral 1 letter l and so on.
          Well this is exactly what I typed.

          Anyway, i would like to understand how can I use it to achieve what I mentioned in my first message, after I install it.

          Thank you,

          Fitzgerald

          Comment


          • #6
            Sorry, yes: you are right about the name. The issue is different. grc1leg2 is by Mead Over and is to be downloaded from his workplace website. The original grc1leg is by Vince WIggins and is to be downloaded from the StataCorp website.

            Code:
            search grc1leg
            gives all the details.

            Otherwise I don't think I've ever used that command. My bias is to avoid graph combine whenever a single legend makes sense in favour of a by() option. Whether that works for you isn't clear to me in the absence of a data example or graph example. But see

            SJ-20-4 gr0085 . The by() option of graph can work better than graph combine
            . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
            4/20 SJ 20(4):1016--1027 (no commands)
            describes whether to use the by() option of graph or
            graph combine for paneled figures

            Comment


            • #7
              Code:
              net install grc1leg2.pkg
              worked just fine on my system just now. The error you reported signals a network connectivity issue, and those are often temporary (either because of problems on the hosting server side, or at your end, or somewhere in between). Just try again a couple times, and if you're still stuck, we can try to troubleshoot.

              Anyway, i would like to understand how can I use it to achieve what I mentioned in my first message, after I install it.
              As always, the help documentation is your friend. Once you have installed the command, do
              Code:
              help grc1leg2
              and see what you can figure out. If you're unable to make it work, post what you tried and the resulting error(s) here, and we can try and help.

              Comment

              Working...
              X