Announcement

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

  • graph combine distorts aspect ratio when combining fewer graphs

    Hello,

    I'm encountering an issue when using the graph combine command to arrange a set of graphs in a grid layout. Specifically, I want to display 10 graphs in a 2x2 layout for visual balance. This is done by producing 3 combined graphs: the first 2 have 4 graphs each and the third has the remaining 2 graphs. However, since the final row contains just two graphs (i.e., a 2x1 grid), Stata stretches the height of these graphs to fill the space, distorting the aspect ratio.

    Below is a reproducible example that illustrates the problem:

    Code:
    clear all
    sysuse auto, clear
    
    cd "" // replace with a folder path
    
    gen obs_order = _n
    xtile mygroup = obs_order, n(6)
    
    foreach yy of numlist 1/6 {
        graph bar price foreign if mygroup == `yy'
            graph save graph_`yy', replace    
    }
    
    // This 2x2 layout looks fine – proportions are preserved
    graph combine graph_1.gph graph_2.gph graph_3.gph graph_4.gph, col(2) row(2)
    
    // This 2x1 layout is distorted – vertical stretching occurs
    graph combine graph_5.gph graph_6.gph, col(2) row(2)

    In the first combined graph (4 graphs in a 2x2 layout), the aspect ratio is preserved as expected. However, in the second combined graph (2 graphs), Stata stretches the graphs vertically, presumably trying to fill space for non-existent graphs 7 and 8.

    Is there a way to prevent Stata from stretching the graphs when combining fewer graphs? Ideally, I’d like to keep the same aspect ratio or dimensions as in the earlier graph combine.

    Thank you in advance for your help!

    Best,
    Hélder

  • #2
    I can't think of a way to do this automatically, but could you use fxsize() and fysize() options to control their size? You may have to make the loop save each graph 2ce- one for each type of combined graph.

    Comment


    • #3
      #1 was cross-posted at https://www.statalist.org/forums/for...g-fewer-graphs -- so see also the answers there

      Comment


      • #4
        Thank you Alecia Cassidy, setting fysize(50) seems the best solution so far, as it fully replicates the graph to the ones with a 2x2 grid. The only catch is the large white space above and below the 2x1 graph, but I managed to handle this by cropping the image in MS Word.

        Comment


        • #5
          Glad it worked!

          Comment

          Working...
          X