Announcement

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

  • -grc1leg- not omitting legend of component graphs


    Hello,

    I'm having problems in generating a combined graph with a single common legend, as it is the purpose of -grc1leg-. I've tried -grc1leg2- without identical results. I've also tried producing subgraphs with the -by(, legend(off))- option, but it gave me not legends anywhere.
    Click image for larger version

Name:	multiplelegends.png
Views:	1
Size:	19.5 KB
ID:	1598807


    In another post here, it seems like Nick Cox suggests -grc1leg- does not handle subgraphs with the -by()- option. Is that the case? Any way around this issue?

    I'm using Stata/IC 14.2 on Windows 10. Please find my code below.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(order_0th order_1st order_2nd order_3rd) str3 Country float E_int
    .7713897514162157 .8983225631889338 .9502321908700299 .9751999295525718 "KOR" 1
    .7728646528002182 .9383212578278355 .9819118726638241 .9942301335562106 "IRL" 1
    .6520159877677851 .9121377064098004 .9747471517401809 .9917984486988558 "IRL" 0
    .6120832068748473 .8152489201542453 .9045947423296314 .9509950438312654 "KOR" 1
    .7631853372424123 .9394807242320112 .9829067108733993 .9945699072222791 "IRL" 1
     .903293987668906 .9781866263244458 .9936282476232506 .9978061162704196 "IRL" 1
     .865287920308868 .9622437133705122 .9871829259446699 .9952220573997735 "IRL" 0
    .9999999999999248 .9999999999999863 .9999999999999963 .9999999999999989 "IRL" 1
    .6792053150007263 .8063989295123989 .8937131164157297 .9441320938002318 "KOR" 1
    .9197390025497783 .9779566782958434 .9927579596463956 .9973200689783972 "IRL" 1
    .6365057955352291 .9023851889266424 .9734745091297393 .9922561223846332 "IRL" 1
    .4225068227500901  .788998764115341 .9046037611433007 .9523722898556336 "KOR" 0
    .9990615485362677 .9995811977144247 .9997887355023127 .9998918138706242 "KOR" 1
    .9182802263367715 .9780545049436485 .9940366116334217  .998259042597569 "IRL" 1
    .8725685337577995 .9672674068354333   .99025852065573 .9967693513075605 "IRL" 1
    .9578451533226735 .9907174081433222 .9971845159005579 .9989958860915611 "IRL" 1
    .8846973398371609 .9720648024371774 .9921325686225014 .9974391757004147 "IRL" 1
    .7335101993068649 .8835785734219438 .9443981517357872 .9724995644900749 "KOR" 1
    .8821281102440207 .9659512714005644  .988734623242631 .9959272584518145 "IRL" 1
    .9466007799343315 .9868004469516986 .9957800546785351 .9984931323030795 "IRL" 1
    end
    label values E_int E_int_label
    label def E_int_label 0 "Capital Intensive", modify
    label def E_int_label 1 "Labour Intensive", modify
    
    foreach v of varlist order_0th order_1st order_2nd order_3rd {
    label variable `v' "mean"
    statplot `v', over(E_int) by(Country, note("")) recast(bar) asyvars yla(, ang(h)) ///
        bar(2, bcolor(forest_green)) bar(1, bcolor(maroon)) ///
         ytitle(`v') xsize(15) ysize(8) ///
         by(, graphregion(fcolor(white) lcolor(white))) scheme(s2color) name(`v', replace)
    }
    *
    grc1leg2 order_0th order_1st order_2nd order_3rd
    Best regards,
    Veridiana

    P.S.: I've benefitted from the Statalist Forum for years, but this is my first post. I hope I made it right, but please let me know if I can improve something. I'm really grateful to you all, especially to Nick Cox, who put some much time in giving us valuable tools and tricks.
    Attached Files
    Last edited by Veridiana Nogueira; 19 Mar 2021, 13:04.

  • #2
    grc1leg2 is from http://digital.cgdev.org/doc/stata/MO/Misc/ and is authored by Mead Over (FAQ Advice #12).

    Code:
    net install grc1leg2.pkg, from (http://digital.cgdev.org/doc/stata/MO/Misc/)

    In another post here, it seems like Nick Cox suggests -grc1leg- does not handle subgraphs with the -by()- option. Is that the case? Any way around this issue?
    I don't think there has been a resolution to this, but see William Lisowski's suggested workaround from #10 of the linked thread below.

    https://www.statalist.org/forums/for...pear-graphs-by

    Comment


    • #3
      Here's a different take. You want 2 x 4 x 2 = 16 means. One design avoids legends altogether with

      countries as panels

      capital and labour intensive as separate variables

      different order as an axis variable.

      I also use C and L as more nearly self-explanatory marker labels, avoid bars and starting at 0, and most eccentrically of all a folded root scale sqrt(p) - sqrt(1 - p), a weaker cousin of logit p = log p - log (1 - p), to stretch values near 1 suitably. Logit scale does even better, but I still prefer to show 1 as an axis label.


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double(order_0th order_1st order_2nd order_3rd) str3 Country float E_int
      .7713897514162157 .8983225631889338 .9502321908700299 .9751999295525718 "KOR" 1
      .7728646528002182 .9383212578278355 .9819118726638241 .9942301335562106 "IRL" 1
      .6520159877677851 .9121377064098004 .9747471517401809 .9917984486988558 "IRL" 0
      .6120832068748473 .8152489201542453 .9045947423296314 .9509950438312654 "KOR" 1
      .7631853372424123 .9394807242320112 .9829067108733993 .9945699072222791 "IRL" 1
       .903293987668906 .9781866263244458 .9936282476232506 .9978061162704196 "IRL" 1
       .865287920308868 .9622437133705122 .9871829259446699 .9952220573997735 "IRL" 0
      .9999999999999248 .9999999999999863 .9999999999999963 .9999999999999989 "IRL" 1
      .6792053150007263 .8063989295123989 .8937131164157297 .9441320938002318 "KOR" 1
      .9197390025497783 .9779566782958434 .9927579596463956 .9973200689783972 "IRL" 1
      .6365057955352291 .9023851889266424 .9734745091297393 .9922561223846332 "IRL" 1
      .4225068227500901  .788998764115341 .9046037611433007 .9523722898556336 "KOR" 0
      .9990615485362677 .9995811977144247 .9997887355023127 .9998918138706242 "KOR" 1
      .9182802263367715 .9780545049436485 .9940366116334217  .998259042597569 "IRL" 1
      .8725685337577995 .9672674068354333   .99025852065573 .9967693513075605 "IRL" 1
      .9578451533226735 .9907174081433222 .9971845159005579 .9989958860915611 "IRL" 1
      .8846973398371609 .9720648024371774 .9921325686225014 .9974391757004147 "IRL" 1
      .7335101993068649 .8835785734219438 .9443981517357872 .9724995644900749 "KOR" 1
      .8821281102440207 .9659512714005644  .988734623242631 .9959272584518145 "IRL" 1
      .9466007799343315 .9868004469516986 .9957800546785351 .9984931323030795 "IRL" 1
      end
      label values E_int E_int_label
      label def E_int_label 0 "Capital Intensive", modify
      label def E_int_label 1 "Labour Intensive", modify
      
      collapse (mean) order_*, by(Country E_int)
      
      reshape long order, i(Country E_int) j(which) string
      rename (order which) (whatever order)
      gen x = real(substr(order, 2, 1)) 
      gen toshow = sqrt(whatever) - sqrt(1 - whatever)
      separate toshow, by(E_int) veryshortlabel 
      
      * mylabels is from SSC 
      mylabels 0.4(0.1)0.9, myscale(sqrt(@) - sqrt(1 - @)) prefix("0") local(yla)
      
      gen text = cond(E_int == 0, "C", "L")  
      set scheme s1color 
      scatter toshow? x, by(Country, note("") legend(off)) xsc(r(-0.3 3.3)) xla(, grid glcolor(gs12) glw(vthin)) ms(none ..) mlabc(blue red) mlabsize(medium ..) mlabpos(0 0) mla(text text) yla(`yla' 1 "1", ang(h)) ytitle(whatever) xtitle(order)

      Click image for larger version

Name:	veridiana.png
Views:	1
Size:	31.2 KB
ID:	1598832

      Comment


      • #4
        Originally posted by Andrew Musau View Post
        grc1leg2 is from http://digital.cgdev.org/doc/stata/MO/Misc/ and is authored by Mead Over (FAQ Advice #12).
        I see your point. The link is broken, but thank you.
        Last edited by Veridiana Nogueira; 19 Mar 2021, 16:31.

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Here's a different take. You want 2 x 4 x 2 = 16 means. One design avoids legends altogether with

          countries as panels

          capital and labour intensive as separate variables

          different order as an axis variable.
          I was just thinking about something on these lines while waiting for replies, but not sure how to put that in practice. Thank you for the code!

          Comment


          • #6
            Regarding the link in post #2 quoted in post #4: although it is not possible to open the link
            Code:
            http://digital.cgdev.org/doc/stata/MO/Misc
            in a web browser, it is possible to issue the commands
            Code:
            net from http://digital.cgdev.org/doc/stata/MO/Misc
            net describe grc1leg2, from(http://digital.cgdev.org/doc/stata/MO/Misc)
            net install grc1leg2.pkg, from(http://digital.cgdev.org/doc/stata/MO/Misc/)
            to access the directory for that user site, to describe grc1leg2, and to install grc1leg2.

            Comment


            • #7
              I agree with Nick Cox that embedding a multi-panel graph (such as those created by graph ..., by() or by graph combine) into another multi-panel graph is likely to produce a result that is hard for the reader to interpret. But since there may be some circumstances where such recursive multiplicity is desireable, I have revised grc1leg2 so that it now accommodates component panels which have been produced by graph ..., by() or by graph combine. Using version 1.4 of grc1leg2, the following code:

              Code:
              * Example generated by -dataex-. To install: ssc install dataex
              cap program drop grc1leg2
              graph drop _all
              clear
              input double(order_0th order_1st order_2nd order_3rd) str3 Country float E_int
              .7713897514162157 .8983225631889338 .9502321908700299 .9751999295525718 "KOR" 1
              .7728646528002182 .9383212578278355 .9819118726638241 .9942301335562106 "IRL" 1
              .6520159877677851 .9121377064098004 .9747471517401809 .9917984486988558 "IRL" 0
              .6120832068748473 .8152489201542453 .9045947423296314 .9509950438312654 "KOR" 1
              .7631853372424123 .9394807242320112 .9829067108733993 .9945699072222791 "IRL" 1
               .903293987668906 .9781866263244458 .9936282476232506 .9978061162704196 "IRL" 1
               .865287920308868 .9622437133705122 .9871829259446699 .9952220573997735 "IRL" 0
              .9999999999999248 .9999999999999863 .9999999999999963 .9999999999999989 "IRL" 1
              .6792053150007263 .8063989295123989 .8937131164157297 .9441320938002318 "KOR" 1
              .9197390025497783 .9779566782958434 .9927579596463956 .9973200689783972 "IRL" 1
              .6365057955352291 .9023851889266424 .9734745091297393 .9922561223846332 "IRL" 1
              .4225068227500901  .788998764115341 .9046037611433007 .9523722898556336 "KOR" 0
              .9990615485362677 .9995811977144247 .9997887355023127 .9998918138706242 "KOR" 1
              .9182802263367715 .9780545049436485 .9940366116334217  .998259042597569 "IRL" 1
              .8725685337577995 .9672674068354333   .99025852065573 .9967693513075605 "IRL" 1
              .9578451533226735 .9907174081433222 .9971845159005579 .9989958860915611 "IRL" 1
              .8846973398371609 .9720648024371774 .9921325686225014 .9974391757004147 "IRL" 1
              .7335101993068649 .8835785734219438 .9443981517357872 .9724995644900749 "KOR" 1
              .8821281102440207 .9659512714005644  .988734623242631 .9959272584518145 "IRL" 1
              .9466007799343315 .9868004469516986 .9957800546785351 .9984931323030795 "IRL" 1
              end
              label values E_int E_int_label
              label def E_int_label 0 "Capital Intensive", modify
              label def E_int_label 1 "Labour Intensive", modify
              
              set graph off
              foreach v of varlist order_0th order_1st order_2nd order_3rd {
              label variable `v' "mean"
              statplot `v', over(E_int) by(Country, subtitle(`v') note("")) recast(bar) asyvars yla(, ang(h)) ///
                  bar(2, bcolor(forest_green)) bar(1, bcolor(maroon)) ///
                   ytitle(mean proportion) xsize(15) ysize(8) ///
                   ylabel(0(.2)1)  ///
                   by(, graphregion(fcolor(white) lcolor(white))) scheme(s2color) name(`v', replace)
              }
              set graph on
              *
              
              grc1leg2 order_0th order_1st order_2nd order_3rd, name(combined, replace) l1tol1title
              produces the following result.

              Click image for larger version

Name:	grc1leg2_combined.png
Views:	1
Size:	155.4 KB
ID:	1599521


              I have taken the liberty of moving the panel labels from the y-axis to the subtitles and adding the y-title "mean proportion" which I infer might be the measure captured by the bars. This change, allows me to demonstrate how grc1leg2 can reduce clutter with the option l1tol1title, which suppresses the redundant y-axis labels and moves one of them to the common "l1" axis label so that it applies to all panels. (The option ytol1title, used when component graphs are single panels, does not work here because the y-axis title produced by the command statplot, and indeed by many multipanel graph commands, is located in l1title, not in ytitle.)

              Instead of using the option ycommon to line up the axes of the four panels, I specified the option ylabel(0(.2)1) for the statplot command.

              As mentioned by @William Lisowsky, the program grc1leg2 can be found and installed from inside Stata with
              Code:
              net describe grc1leg2, from(http://digital.cgdev.org/doc/stata/MO/Misc)
              Some users might prefer to type
              Code:
              view net describe grc1leg2, from(http://digital.cgdev.org/doc/stata/MO/Misc)
              in order to see the package description and clickable links in their viewer instead of in their results window.

              Comment


              • #8
                Originally posted by Mead Over View Post
                I agree with Nick Cox that embedding a multi-panel graph (such as those created by graph ..., by() or by graph combine) into another multi-panel graph is likely to produce a result that is hard for the reader to interpret. But since there may be some circumstances where such recursive multiplicity is desireable, I have revised grc1leg2 so that it now accommodates component panels which have been produced by graph ..., by() or by graph combine.
                I've also decided to change the plot in this case. I initially had all industries. When I decided to go for group means, the problem with the legend stuck me. Nevertheless, your fixture certainly might be useful for me and others in the future.

                I believe this concludes my enquiry. Thank you for all who contributed.

                Comment

                Working...
                X