Announcement

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

  • Margin on left side of twoway plot depending on y range

    Hi, I am trying to plot graphs where the label of the y axis is horizontal. I am finding that, depending on the value of the range of the y axis, I sometimes get a very large empty margin on the left side of the graph.

    The first twoway graph generated in the following code has this empty margin, and the second does not. This is despite including margin(zero).

    How do I get rid of the margin on the left for example 1?

    Code:
    clear
    input float(_b_ _min_ _max_ _year_)
    -.027993575   -.0550683 -.0009188477 2007
    -.007819422 -.020521745   .004882903 2008
    -.012764178  -.02672572  .0011973644 2009
              0           .            . 2010
     -.02697954  -.05132534  -.002633733 2011
    -.033307176  -.06746621  .0008518519 2012
    -.028319916 -.064195335   .007555502 2013
    -.008611818  -.07119201    .05396837 2014
     -.03748605  -.10149958   .026527485 2015
    end
    
    * ex. 1
    tw ( rcap _min_ _max_ _year_ ) ( scatter _b_ _year_, m(o) c(l) lp(line) ), ///
        legend(off) xtitle("Year", size(large)) ytitle("") ///
        xlabel(2007(1)2015,angle(60) labsize(large)) ///
        ylabel(-0.15(0.05)0.05,labsize(large) angle(0)) ///
        yline(0, lcolor(black) lpattern(dash)) ///
        xline(2010, lcolor(black) lpattern(dash)) graphregion(color(white) margin(zero))
    
    * ex. 2
    tw ( rcap _min_ _max_ _year_ ) ( scatter _b_ _year_, m(o) c(l) lp(line) ), ///
        legend(off) xtitle("Year", size(large)) ytitle("") ///
        xlabel(2007(1)2015,angle(60) labsize(large)) ///
        ylabel(-0.1(0.05)0.05,labsize(large) angle(0)) ///
        yline(0, lcolor(black) lpattern(dash)) ///
        xline(2010, lcolor(black) lpattern(dash)) graphregion(color(white) margin(zero))
    Attached Files

  • #2
    Code:
    ysc(outergap(-10))

    Comment


    • #3
      Thanks for the suggestion, Andrew. My only concern with that solution is that I am trying to write automated code in which the y scale varies with different data. Including that line of code fixes example 1, but if applied to example 2, it cuts off the numbers.

      Comment


      • #4
        It seems to be triggered by the -ylabel()- option. So be consistent on the starting point. For the first graph, as you do not want to show -0.1, you can specify the -ylabel- option as

        Code:
         
         ylabel(-0.1 "" -0.15(0.05)0.05,labsize(large) angle(0))
        So just embed -0.1 "" to all -ylabels-. For example, there is no problem with

        Code:
         ylabel(-0.1 "" -0.1(0.05)0.05,labsize(large) angle(0))

        Comment


        • #5
          Hello, I know this post is old, but I have the same question and I don't understand the answer given. Is there someone who can explain why this behavior occurs (different margins depending on the y-axis labels, even when graphregion(margin(zero)) is specified)? Thank you very much in advance.

          Comment


          • #6
            On why, you need to contact Technical Services who will be in touch with someone who has knowledge on the inner workings of graph twoway.

            I don't understand the answer given.
            Specifically, what don't you understand?

            Comment


            • #7
              As I understand it

              Code:
              graphregion(margin(zero))
              isn't consistent with having axis labels and so my guess is that it is just ignored. I don't have an answer on why horizontal y axis labels can be associated with different amounts of outer space in otherwise similar-seeming circumstances.

              Comment

              Working...
              X