Announcement

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

  • Graph combine - ordering / formatting / centering

    Dear All,

    I would like to combine 4 scatterplots of the same size using e.g. graph combine.

    The challenge that arises is that I would like them to be combined as follows:

    Row1: Graph1 (centered)
    Row2: Graph2 and Graph3
    Row1: Graph4 (centered)

    Can this be done in Stata? That'd be stellar!

    Many thanks in advance.


  • #2
    this can be done as follows: first, combine 2 and 3 (call it 23) and then combine, vertically, 1, 23 and 4 - I know of no way to do this in one step but this two-step solution does work

    Comment


    • #3
      For centering, you will need the -imargin()- option of gr combine or place the margins in the original graphs. gr combine rescales objects within the graph, so there is some work for you to achieve perfection. But as Rich states, you will need a combination of combined graphs. In general, you will want to use the -by()- option instead of gr combine whenever feasible; see https://journals.sagepub.com/doi/pdf...36867X20976341.

      Code:
      sysuse auto, clear
      forval i=1/4{
          local opt= cond(`i'==1|`i'==4, "xtitle(, size(small)) msize(.7) ytitle(, size(small)) xlab(, labsize(small)) ylab(, labsize(small))", "")
          scatter mpg weight, saving(gr`i', replace) `opt'
      }
      gr combine gr1.gph, row(1) imargin(50 50 0 0) saving(gr_1, replace)
      gr combine gr2.gph gr3.gph, row(1) saving(gr_2, replace)
      gr combine gr4.gph, row(1) imargin(50 50 0 0) saving(gr_3, replace)
      gr combine gr_1.gph gr_2.gph gr_3.gph, col(1)
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	53.0 KB
ID:	1738730

      Last edited by Andrew Musau; 03 Jan 2024, 04:29.

      Comment


      • #4
        That's brilliant, many thanks to both of you, Rich and Andrew. Worked like a charm!

        Comment

        Working...
        X