Announcement

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

  • Having all legends at the bottom: graph combine

    I have two graphs and I need to combine the two. The idea is to show a break between the series lotsize2 and floorspace. Both graphs have two lines each and I want the legend for all 4 lines at the bottom. I have tried graph combine and grc1leg2 both but they only pick the legend from one of the two not both. Here is my code. Any help is appreciated.

    line lotsize2 year, xscale(off) ylabel(12000(500)14000, ang(h) labsize(vsmall)) ytitle("") lpattern(dash) || ///
    line rooms year, xscale(off) yaxis(2) ylabel(4(0.5)6, ang(h) labsize(vsmall) axis(2)) ytitle("", axis(2)) lpattern(solid) graphregion(color(white)) name(gr1,replace)

    line floorspace year, ylabel(1500 "1500 " 2000 "2000 " 2500 "2500 " 3000 "3000 " 3500 "3500 ", ang(h) labsize(vsmall)) ytitle("") lpattern(shortdash_dot) yscale(range(1500 3500)) || ///
    line bedrooms year, yaxis(2) ylabel(1.5(0.5)3.5, ang(h) labsize(vsmall) axis(2)) ytitle("", axis(2)) color(black%33) lpattern(solid) yscale(range(1.5 3.5) axis(2)) graphregion(color(white)) name(gr2,replace)

    grc1leg2 gr1 gr2, rows(2) imargin(tiny) commonscheme l1title("square feet", size(small)) graphregion(color(white))
    graph combine gr1 gr2, rows(2) imargin(tiny) commonscheme l1title("square feet", size(small)) graphregion(color(white))


    Click image for larger version

Name:	figure_4_test.png
Views:	1
Size:	55.8 KB
ID:	1756113

  • #2
    Not what you're asking but nevertheless consider multiline from SSC as one alternative. Working backwards, a personal slogan runs

    Lose the legend! Kill the key! (if you can)

    on the grounds that a legend enforces mental back and forth which is not in itself a good thing if direct labelling (*) is possible.

    labeling if you prefer.

    Code:
    . clear 
    
    . set obs 42 
    
    . gen year = 1979 + _n
    
    . set seed 2803 
    
    . gen lotsize = rnormal(13000, 500)
    
    . gen floorspace = rnormal(2500, 500)
    
    . gen bedrooms = rnormal(2.5, 0.5)
    
    * you start around here 
    . multiline lotsize floorspace bedrooms year 
    
    . label var lotsize `" "longer text" "here" "'
    
    . label var floorspace `" "is entirely" "possible" "'
    
    . label var bedrooms `" "depending on" "variable labels" "'
    
    . multiline lotsize floorspace bedrooms year, xtitle("")
    Click image for larger version

Name:	multiline.png
Views:	1
Size:	46.7 KB
ID:	1756119

    Comment


    • #3
      For more on multiline see https://www.statalist.org/forums/for...ailable-on-ssc

      Comment


      • #4
        Nick thanks a lot for your response! Advice of losing the legend well taken!

        I have two questions on multiline:

        (1) How do I fix the range for each sub-line plot? I need to produce the same figure for 4 different regions, and for visual comparability I need the range to be the same. I can't see anyway to do this in multiline documentation.
        (2) Is it possible to get rid of the horizontal lines between plots?

        Thank you in advance/

        Comment


        • #5
          You seem to be talking about a quite different case from #1 in which there were different variables and quite different ranges.

          In terms of your questions in #4

          (1)

          If you have different regions and want the same range on the y axis, and that doesn't happen through use of ylabel(),then you should perhaps be switching to using by(). That may need some different data layout but advice and examples are available at https://journals.sagepub.com/doi/pdf...36867X20976341

          (2)

          From my point of view as command author, the use of multiple panels and dividing lines in
          Code:
           multiline
          helps to impart absolute clarity about which variable or subset is which and wanting to undo that is somewhere between puzzling and perverse. More diplomatically put, if that is what you want, you should go back to the kind of code you were using in #1.

          Comment


          • #6
            Nick, I should clarify: I need to reproduce #1 4 times. That is, the same multiline plot for 4 different regions, where for each region, I have 4 series (lot size, floorspace, number of rooms, number of bedrooms), with different ranges that multiline very elegantly captures. The issue is that for each line I want to pre-set the range for all regions. For context, assume for one region lot_size varies from 1500 to 2500 and for another between 1000 to 2000. I want the scale to run from 1000 to 2500 for both regions for lot_size.

            Point well taken on (2).

            Thank you for engaging and for your time!

            Comment


            • #7
              I see. I don't think multiline can help with this more complicated problem, which wasn't mentioned in #1.

              I don't think I can say in advance what would help easily with this more complicated problem. I really need a data example to play with.

              If you gave a real(istic) data example, odds are that other people would engage with this thread too.

              As I understand it you have four variables for four regions, and if so, there are many possible choices.

              Superimposing 16 series on one plot. That might be a complete mess, or else the best thing you can do.

              Regions define graph panels, or variables define graph panels. Repetition for variables, or repetition for regions.

              Each graph is to be viewed separately, but the scales should be consistent.

              All graphs should be viewable at once.

              Comment


              • #8
                Minahil Aamir wrote "I have tried graph combine and grc1leg2 both but they only pick the legend from one of the two [graphs] not both."

                In fact, -grc1leg2- can pick legend keys from both of two combined graphs. Within the help file for -grc1leg2-, see:

                Code:
                Examples 3.10a, b and c: Assembling a composite legend using the hidelegendfrom option
                My ado command -grc1leg2- is easiest to describe or install with the command:

                Code:
                view net describe grc1leg2, from("http://digital.cgdev.org/doc/stata/MO/Misc")

                Comment

                Working...
                X