Announcement

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

  • Graph combine and grc1leg create large empty space at the top of graph with ycommon

    Hello!

    I am having issues with combining graph. Both
    Code:
    graph combine
    and
    Code:
    grc1leg
    create a large empty space at the top of a graph and I would like to find an elegant solution to solve the issue. The graph I obtain is:
    Click image for larger version

Name:	gc.png
Views:	1
Size:	46.5 KB
ID:	1676900


    As you can see, there is a lot of not-so-useful space at the top. There are little tricks I could use to shrink it down but I would rather like a piece of code to do it more systematically.

    The code I typed was:
    Code:
    serrbar meandv sddv year, yscale(range (0 100)) ylabel(0 50 100) xscale(range (2008 2019)) xlabel(2008 2012 2016 2019) xtitle("Year") ytitle("Mean of s1") recast(rarea) yline(50, lcolor(gs12))  graphregion(color(white)) mvopts(mcolor(black)) fcolor(gs12%30) saving(des1.gph)
    serrbar meandv2 sddv2 year, yscale(range (0 100)) ylabel(0 50 100) xscale(range (2008 2019)) xlabel(2008 2012 2016 2019) xtitle("Year") ytitle("Mean of s2") recast(rarea) yline(50, lcolor(gs12)) graphregion(color(white)) mvopts(mcolor(black)) fcolor(gs12%30)  saving(des2.gph)
    graph combine des1.gph des2.gph, ycommon graphregion(color(white))
    grc1leg des1.gph des2.gph, ycommon graphregion(color(white))
    Thank you very much,

    Best,
    Last edited by Pierr Exe; 08 Aug 2022, 07:13.

  • #2
    Data example please

    Comment


    • #3
      Or try -grc1leg2- from Mead Over - see
      Code:
      net describe grc1leg2, from(http://digital.cgdev.org/doc/stata/MO/Misc)
      - I am not sure if it helps but this -grc1leg2- is more up to date.

      Comment


      • #4
        This looks like 12 observations for 5 variables, so as Jared Greathouse asks, a data example would allow some testing of alternatives.

        Comment


        • #5
          Do you have the same problem if you omit the ycommon option?
          I had a similar issue recently using grc1leg2 to combine graphs that already had the same scale for the y-axis. My final graph ended up looking better without the ycommon option than it did with it, though I can offer no explanation for why that is.

          Comment


          • #6
            One technique is to recast drawing two (or more) graphs as a problem for a by() option. graph uses machinery to make many details consistent between panels. See https://journals.sagepub.com/doi/pdf...36867X20976341 for a write-up of the idea.

            Here is some code to show technique:

            Code:
            clear 
            set obs 12 
            gen year = 2007 + _n 
            set seed 2803 
            gen meandv = rnormal(50, 10)
            gen meandv2 = rnormal(50, 10)
            gen sddv = rnormal(10, 1)
            gen sddv2 = rnormal(10, 1)
            
            rename (meandv sddv) (=1)
            
            reshape long meandv sddv, i(year) j(which)
            
            gen low = meandv - sddv 
            gen high = meandv + sddv 
            label def which 1 something 2 sensible 
            label val which which 
            
            set scheme s1color 
            
            twoway rarea low high year, color(blue*0.2) || line meandv year, by(which, note("") legend(off)) color(blue) xla(2008 " 2008" 2012 2016 2019 "2019 ") ytitle(mean {&plusmn} SD of whatever)  xtitle("")



            Click image for larger version

Name:	serrbar.png
Views:	1
Size:	53.8 KB
ID:	1676997

            Comment


            • #7
              Dear all,

              Thank you for your help and apologies for the late reply. Omitting the
              Code:
              ycommon
              for both
              Code:
              graph combine
              and
              Code:
              grc1leg2
              produces decent results although, obviously, the y-axis differs between the two graphs, which is not ideal. Going for the latter option; i.e. recasting drawing two graphs, it is a nice work-around with the desired outcome.

              As for the data, it is time-series cross-section, spanning the years 2008-2019 with dependent variable being a percentage. In total, about 32k observations.

              Thank you all again for your precious help!

              Best,

              Comment

              Working...
              X