Announcement

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

  • grc1leg ignoring aspect ratio

    I'm using the grc1leg command and find I cannot change the aspect ratio with the ysize() and xsize() options. Below is some example code, borrowed from another post, that creates four graphs.
    Code:
    clear
    input byte r_id str26 region float(period year) double(gfd shr kme klf)
    1 "East Asia & Pacific"        1 1  8325.703482570614 221713507.51180354 312545535391.22266  9.884943733931932
    1 "East Asia & Pacific"        2 2  9962.102881752555  291994199.0371205  374296140523.1998 10.281044165113197
    2 "Europe & Central Asia"      1 1   24102.8204969368   538919571.786615 538401194443.77637 19.022858084454136
    2 "Europe & Central Asia"      2 2  25799.98590965781  654494471.3396385  581745338410.1671 23.309416601936224
    3 "Latin America & Caribbean"  1 1  9455.280580949593  80081604.26769644  76151826017.24394  6.093767684310448
    3 "Latin America & Caribbean"  2 2   9545.11053660585 106220095.91957214  98404982310.05264  7.355575546132802
    4 "Middle East & North Africa" 1 1  7373.541711250463   89946551.4761219  81922279949.52919 16.905612650025958
    4 "Middle East & North Africa" 2 2 7777.9616878091565  99544773.86252138 106317425321.04172 19.484252374025836
    5 "North America"              1 1  49559.27810369779           83961914       2.209272e+11  7.247645902684366
    5 "North America"              2 2  53454.28768786681           98022165 270455750000.00006  7.239042277091585
    6 "South Asia"                 1 1 1368.5156808676866  12190005.91249332        2.40586e+10  11.19949571592668
    6 "South Asia"                 2 2 1780.9751084779448 23091459.198763825        3.49224e+10 10.671254320423737
    7 "Sub-Saharan Africa"         1 1  1645.103030610854 38776587.938939884 29995171741.764538 10.925456728424516
    7 "Sub-Saharan Africa"         2 2 1682.6993478548713  45598841.52158082  32372205773.37823  10.55520839362721
    end
    label values year fiveyr
    label def fiveyr 1 "2010-2014", modify
    label def fiveyr 2 "2015-2019", modify
    
    local graphs
    foreach var in gfd shr kme klf{
    gr hbar `var', over(year) over(region) asyvars bar(1, color(red%50)) bar(2, color(blue%50))scheme(s1color) saving(`var', replace)
    local graphs "`graphs' `var'.gph"
    }
    And now I combine the graphs using grc1leg, but the xsize() and ysize() options appear to have no effect.

    Code:
    grc1leg `graphs', scheme(s1color) ysize(9) xsize(6.5)
    If instead I use the grc1leg2 command, the result is the same.

  • #2
    https://www.statalist.org/forums/for...-year-averages gave an alternative solution, and I'm optimistic that it allows tuning of the aspect ratio.

    Comment


    • #3
      Thanks, Nick. Are you referring to the solution you proposed in that other thread, using multidot instead of grc1leg?

      Comment


      • #4
        Indeed.

        Comment


        • #5
          Unfortunately, there are other instances when multidot is not an option. Is there any way to get grc1leg to pay attention to ysize() and xsize()?

          Comment


          • #6
            The problem is specific to the grc1leg command. The related graph combine command responds well to the xsize() and ysize() options -- e.g.,
            Code:
             graph combine `graphs', scheme(s1color) ysize(9) xsize(6.5)

            Comment


            • #7
              You may want to check out grc1leg2 by Mead Over, available from

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

              Comment


              • #8
                A work-around for this is to use graph display to redraw the graph after grc1leg produces the graph.
                Code:
                graph display, ysize(9) xsize(6.5)
                We will look into why grc1leg is not respecting these options.

                Comment


                • #9
                  Thanks, Jeff Pitblado (StataCorp) !
                  Andrew Musau : Thanks for the suggestion. Unfortunately grc1leg2 has the same problem.

                  Comment


                  • #10
                    Thanks to paulvonhippel for pointing out that neither my -grc1leg2- nor its progenitor -grc1leg- (by Vince Wiggins (StataCorp) would accept the options -xsize(#)- and -ysize(#)-.

                    In response to this discussion, and building on Jeff Pitblado (StataCorp)'s suggestion to use -graph display-, I have updated -grc1leg2- to version 1.60 so that it now handles the options -xsize(#)- and -ysize(#)- as well as the other options of Stata's -graph display- command. Here's a modified version of paulvonhippel 's code that demonstrates some of the newly enabled options. Note that all of these options are available from -grc1leg2-'s dialog. The revised help file documents these options and includes an example of their application.

                    Code:
                    clear
                    cap graph drop _all
                    
                    input byte r_id str26 region float(period year) double(gfd shr kme klf)
                    1 "East Asia & Pacific"        1 1  8325.703482570614 221713507.51180354 312545535391.22266  9.884943733931932
                    1 "East Asia & Pacific"        2 2  9962.102881752555  291994199.0371205  374296140523.1998 10.281044165113197
                    2 "Europe & Central Asia"      1 1   24102.8204969368   538919571.786615 538401194443.77637 19.022858084454136
                    2 "Europe & Central Asia"      2 2  25799.98590965781  654494471.3396385  581745338410.1671 23.309416601936224
                    3 "Latin America & Caribbean"  1 1  9455.280580949593  80081604.26769644  76151826017.24394  6.093767684310448
                    3 "Latin America & Caribbean"  2 2   9545.11053660585 106220095.91957214  98404982310.05264  7.355575546132802
                    4 "Middle East & North Africa" 1 1  7373.541711250463   89946551.4761219  81922279949.52919 16.905612650025958
                    4 "Middle East & North Africa" 2 2 7777.9616878091565  99544773.86252138 106317425321.04172 19.484252374025836
                    5 "North America"              1 1  49559.27810369779           83961914       2.209272e+11  7.247645902684366
                    5 "North America"              2 2  53454.28768786681           98022165 270455750000.00006  7.239042277091585
                    6 "South Asia"                 1 1 1368.5156808676866  12190005.91249332        2.40586e+10  11.19949571592668
                    6 "South Asia"                 2 2 1780.9751084779448 23091459.198763825        3.49224e+10 10.671254320423737
                    7 "Sub-Saharan Africa"         1 1  1645.103030610854 38776587.938939884 29995171741.764538 10.925456728424516
                    7 "Sub-Saharan Africa"         2 2 1682.6993478548713  45598841.52158082  32372205773.37823  10.55520839362721
                    end
                    label values year fiveyr
                    label def fiveyr 1 "2010-2014", modify
                    label def fiveyr 2 "2015-2019", modify
                    
                    local graphs
                    local thisscheme s1mono
                    
                    foreach var in gfd shr kme klf {
                        gr hbar `var', over(year) over(region) asyvars scheme(`thisscheme') saving(`var', replace)
                        local graphs `graphs' `var'.gph
                        local thisscheme s1color
                    }
                    
                    cap prog drop grc1leg2
                    
                    *    Paul von Hippel's requested syntax, when component graphs have different graph schemes
                    grc1leg2 `graphs', ysize(9) xsize(6.5) name(demo1, replace)
                    
                    *    But given the choice of horizontal bars, switch the aspect ratio so the x-dimension is longer than the y-dimension.
                    *    This example also shows that -grc1leg2- can now impose an overall scheme, overriding the original schemes
                    grc1leg2 `graphs', xsize(9) ysize(4) name(demo2, replace) scheme(s1rcolor)
                    
                    *    -grc1leg2- can now deploy all of the -graph display- options, which are also available from its dialog
                    *    Here the option -margins(vlarge)- makes extra room on all four margins of the combined graph
                    grc1leg2 `graphs', margins(vlarge) xsize(9) ysize(4) name(demo3, replace) scheme(s1manual)
                    
                    *    To see the empty dialog box
                    db grc1leg2
                    Here is the combined graph named -demo2- which has a modified aspect ratio and overrides the the graph schemes of the original graphs to impose a uniform scheme on the combined graph and all of its components.
                    Click image for larger version

Name:	demo2.png
Views:	2
Size:	203.6 KB
ID:	1614927

                    To install or update the new version:
                    Code:
                    view net describe grc1leg2, from("http://digital.cgdev.org/doc/stata/MO/Misc")
                    Attached Files
                    Last edited by Mead Over; 16 Jun 2021, 10:07.

                    Comment


                    • #11
                      Here's another approach to the same underlying problem. Alphabetical order for regions is probably dopey, I would change the units of two variables to avoid scientific notation, and there may be good reason for the order gfd to klf -- but those are separate issues and easily fixed -- given a specification of a better order.


                      Code:
                      clear
                      
                      input byte r_id str26 region float(period year) double(gfd shr kme klf)
                      1 "East Asia & Pacific"        1 1  8325.703482570614 221713507.51180354 312545535391.22266  9.884943733931932
                      1 "East Asia & Pacific"        2 2  9962.102881752555  291994199.0371205  374296140523.1998 10.281044165113197
                      2 "Europe & Central Asia"      1 1   24102.8204969368   538919571.786615 538401194443.77637 19.022858084454136
                      2 "Europe & Central Asia"      2 2  25799.98590965781  654494471.3396385  581745338410.1671 23.309416601936224
                      3 "Latin America & Caribbean"  1 1  9455.280580949593  80081604.26769644  76151826017.24394  6.093767684310448
                      3 "Latin America & Caribbean"  2 2   9545.11053660585 106220095.91957214  98404982310.05264  7.355575546132802
                      4 "Middle East & North Africa" 1 1  7373.541711250463   89946551.4761219  81922279949.52919 16.905612650025958
                      4 "Middle East & North Africa" 2 2 7777.9616878091565  99544773.86252138 106317425321.04172 19.484252374025836
                      5 "North America"              1 1  49559.27810369779           83961914       2.209272e+11  7.247645902684366
                      5 "North America"              2 2  53454.28768786681           98022165 270455750000.00006  7.239042277091585
                      6 "South Asia"                 1 1 1368.5156808676866  12190005.91249332        2.40586e+10  11.19949571592668
                      6 "South Asia"                 2 2 1780.9751084779448 23091459.198763825        3.49224e+10 10.671254320423737
                      7 "Sub-Saharan Africa"         1 1  1645.103030610854 38776587.938939884 29995171741.764538 10.925456728424516
                      7 "Sub-Saharan Africa"         2 2 1682.6993478548713  45598841.52158082  32372205773.37823  10.55520839362721
                      end
                      label values year fiveyr
                      label def fiveyr 1 "2010-2014", modify
                      label def fiveyr 2 "2015-2019", modify
                      
                      rename (gfd shr kme klf) (y=)
                      
                      reshape long y, i(region year) j(which) string
                      
                      gr hbar y, over(year) over(region) by(which, xrescale note("")) scheme(s1color)  asyvars ytitle("means") xsize(9)
                      Click image for larger version

Name:	mead_over_prob.png
Views:	1
Size:	77.4 KB
ID:	1615032

                      Comment

                      Working...
                      X