Announcement

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

  • Graph combine: is there a way to align plot-regions?

    Is there a way to align the individual plotregions when using graph combine that isn't just play-around-until-it-looks-ok(-ish)?

    Here is a simple example:
    Code:
    twoway function 1, name(a) nodraw ytit("Y is 1", orientation(hor))
    twoway function x, name(b) nodraw ytit("Y is equal to X", orientation(hor))
    graph combine a b, cols(1)
    This produces the below graph, and the x scales don't line up.

    Click image for larger version

Name:	combine.png
Views:	1
Size:	26.6 KB
ID:	1453979


    The best I can come up with is adding spaces to the the shorter title until the plotregions line up.
    To pre-empt the 'don't use graph combine' comments – I do need it here. Using the by() option would align the subplots automatically, but I can't use by() for this specific graph.

    Thanks, Tim

  • #2
    if you can live with vertical titles on the Y axis, you can use the orientation sub-option; see
    Code:
    help textbox_options
    you might also try keeping the orientation horizontal but putting the Y axis title for the second graph on multiple lines - the same help file discusses this
    Last edited by Rich Goldstein; 18 Jul 2018, 08:15.

    Comment


    • #3
      Thanks for the excellent reproducible example. It inspired me to go hunting.

      I don't have good news. My usual approach to fiddling with graphs, since whatever I need is usually 8 links deep into the documentation, is to open the graph in the graph editor and click on everything in sight until by trial and error I can find something that does what I want, at which point I know what I changed - e.g., an axis title property - and that helps me in my search through the documentation.

      In this case, I was able to find no option that controls the size of the plot area on the two graphs, either separately on each graph, or as an option in the graph combine to make the plot areas identical. Nor was I able to specify the size of the text box used for the y axis label. Adding trailing blanks to the label doesn't help, they get trimmed. Adding leading blanks does the trick, approximately, and perhaps exactly if a monospace font were chosen for the text.

      The only thing I found that will achieve what you want automatically is to give up on horizontal axis labels.

      Comment


      • #4
        Aha, success. Rich's pointer to the textbox options led to this.
        Code:
        graph drop _all
        twoway function 1, name(a) nodraw ytit("Y is 1", width(20) orientation(hor))
        twoway function x, name(b) nodraw ytit("Y is equal to X", width(20) orientation(hor))
        graph combine a b, cols(1)

        Comment


        • #5
          Fantastic, thank you William Lisowski ! This is exactly what I was looking for and I'm shocked that I've not come across it until now.

          Rich Goldstein – I could probably live with vertical titles but in my non-toy example there are 7 stacked two-panel graphs and the titles are too long to fit vertically.

          Thanks both. Tim

          Comment


          • #6
            I will note that I have been unable to reproduce the textbox width option using the Graph Editor. That suboption just doesn't show up. Sigh. If someone else knows the secret, please share it with us. I'm running Stata/SE 15.1 for Mac (64-bit Intel) Revision 27 Jun 2018.

            Comment

            Working...
            X