Announcement

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

  • Graph sizing and ylabel(...) specification

    Colleagues:

    I'm stumped on how/why my graph is resized in what strikes me as a counterintuitive way based on how ylabel is specified. I'm hoping there's a simple option I can use so that regardless of the ylabel specification the x-axis will have the same length. I'm generating a series of these graphs, each with a different ylabel, and hope to have them all align.

    Compare the following graphs—
    Click image for larger version

Name:	exg1.png
Views:	1
Size:	83.7 KB
ID:	1475901
    Click image for larger version

Name:	exg2.png
Views:	1
Size:	78.6 KB
ID:	1475902


    The twoway command is long and messy (displayed at the end of the posting), but key element is
    Code:
    ylab(`ll'(.1)`ul',...)
    The only difference between the commands generating these two graphs is that for the first I specify
    Code:
    local ll=-.301
    local ul=.099
    while for the second I specify
    Code:
    local ll=-.3
    local ul=.1
    Any suggestions are welcome. (I suspect this is an easy fix, but it is eluding me.) Thanks in advance.

    P.S. Here's the full command
    Code:
    twoway (bar y frqorder if frqorder==2|frqorder==8|frqorder==14|frqorder==20, yline(0, lcolor(black*.25)) base(-.3) barw(3) fcolor(%20) lw(0))  (scatter  penonpar1 penonpar2 frqorder in 1/24, mcolor(ebblue orange) msym(d s) yline(0, lcolor(black*.25)) msize(*1.25 *1.25) ylabel(`ll'(.1)`ul', angle(360)) xlabel(1(1)24 , val angle(45) labsize(*.85) tpos(o)) legend(rows(1) pos(12) order(2 3) region(lw(0) fcolor(bg)) label(2 "Age 18-44 {&rarr} Age 45-64") label(3 "Age 45-64 {&rarr} Age 65+") ) xti("{bf:q}") l2("PE{sub:{bf:q}}", orientation(horizontal))  xsc(r(.5 24.5)))

  • #2
    Does it help if you fix the graph width using the xsize() option? E.g.,

    Code:
    twoway (bar...., xsize(5))

    Comment


    • #3
      Thanks Andrew. That's a good idea, but unfortunately the same problem arises when the same xsize(.) is set for the different ylabels. I tried specifying xsize in both the bar and the scatter and it made no difference.

      Comment


      • #4
        I guess (!) that it has to do with the relative sizes Stata applies to the graphs. I am not sure but the last articles by Ben Jann in Stata Journal (part 1 https://www.stata-journal.com/articl...article=gr0073 part 2 https://www.stata-journal.com/articl...ticle=gr0073_1 ) shed some light on it. From reading the articles I guess you may be able to fix the sizes by providing exact sizes in inch, points ...
        But I do not know how to do this in your case or if it is possible...

        Comment


        • #5
          Thanks Marc. I'll take a look at those SJ articles. As a stopgap I tried "padding" the values in the ylabel with blanks. It's not exact (probably since it's not a fixed-width font) but it comes pretty close.
          Code:
           ylabel(-.3 "   -.3" -.2 "   -.2" -.1 "   -.1" 0 "   0" .1 "   .1",...)
          But the Jann articles may be what I need.

          Comment


          • #6
            I am not sure why you want to specify
            Code:
            local ll=-.301
            local ul=.099
            rather than -0.3(0.1)0.1. If you really do want that, then the rest of this may not be useful.

            I see here a precision problem rising as a consequence of binary approximations failing to be exact for multiples of 0.1.

            One way to insist on what you want is to use mylabels (SSC).

            I get this

            Code:
            . mylabels -0.3(0.1)0.1, myscale(@) local(yla)
            -.3 "-.3" -.2 "-.2" -.1 "-.1" 0 "0" .1 ".1"
            The text within quotation marks will be shown literally, and the macro contents will can be used directly.

            Comment


            • #7
              Thanks Nick. That's most helpful.

              For the record, the "-.301" etc. was just for my Statalist example. In the real work, however, some graphs use labels with just two characters (e.g. .1) while others use four (e.g. .025).

              Comment

              Working...
              X