Announcement

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

  • Likely a very simple question: what is the syntax for adjusting the y axis position offset?

    Greetings,

    I'm running Stata 15 on OSX. I'm struggling to figure out how to adjust the position of the y-axis title without resorting to the Graph editor. I initially tried yscale(, titlegap()) but this merely serves to set the gap between the yaxis labels and the title. What I instead want to do is reposition the title while keeping the y-axis where it is. This can be achieved in the Graph editor in the following menu (i.e. Axis properties-->Title--Advanced--Offset):

    Click image for larger version

Name:	yaxis_offset.jpeg
Views:	1
Size:	1.19 MB
ID:	1534898


    My basic question is how to perform the same exact function via stata syntax. Thank you for your help!

  • #2
    Zach: Specifying explicitly your ylabel and ytitle may do the trick:
    Code:
     scatter y x, ylab(.25(.05).5) yti("This is my y-axis title")
    If that doesn't work you might try something like:
    Code:
    scatter y x, ylab(.25 ".25" .30 ".30" .35 ".35" .40 ".40" .45 ".45" .50 ".50") yti("This is my y-axis title")

    Comment


    • #3
      Hey John,

      Thanks for the reply. The syntax you suggest only relates to the content of the title and the values of the y-axis. How do I offset the y-title to the left (i.e. towards the edge of the graph)?

      Comment


      • #4
        I think you want to look at:
        Code:
        help title_options
        and then scroll down, under suboptions to "position(clockposstyle) and ring(ringposstyle)" - the "ring()" suboption is what you want to read about

        Comment


        • #5
          Struggling to understand what to do. I tried:

          Code:
          ytitle("Z-Score", ring(4) pos(9))
          ...but stata returned a 'opting ring() not allowed' message. Any suggestions?


          Comment


          • #6
            I was recently dealing with the same problem of moving the y-axis title, and figured out the solution by reading this Statalist post:
            https://www.stata.com/statalist/arch.../msg00838.html

            Essentially, the "X-Offset" and "Y-Offset" options in the Graph Editor dialog box are not exposed through normal Stata graph options. However, you can achieve the same effect with the undocumented "gr_edit" command that manipulates the graph properties directly. The relevant command to replicate the "Offset" dialog box options is "DragBy", which specifies an offset to add to the height and width (interestingly, the command is always relative to the current position--so if you execute it multiple times, it continues to move in that direction, and you can enter negative numbers to move the other way). Here is a MWE:
            Code:
            sysuse auto
            twoway (scatter price headroom), title(My Graph)
            gr_edit yaxis1.title.DragBy 40 10
            gr_edit yaxis1.title.DragBy -83 -5
            The result looks a little weird in terms of the blank space left on the y-axis. I found I could deal with this by playing around with the titlegap and outergap options, like this example putting the axis title horizontally at the top:
            Code:
            twoway (scatter price headroom), ysc(titlegap(-8) outergap(5)) title(My Graph)
            gr_edit yaxis1.title.DragBy 41 0
            gr_edit .yaxis1.title._set_orientation horizontal
            Another option (without using the offsets) to get a horizontal title at the top of your y-axis is this way:
            Code:
            twoway (scatter price headroom), ytitle(, placement(n) orient(horizontal)) ylab(,angle(horizontal)) ysc(titlegap(-10) outergap(0))

            Comment


            • #7
              I think there's a better way in many cases, which also involves undocumented features. In my experience (N=1), using the record button in the graph editor to log the effect of entering values for X and Y offset produces not a .DragBy command in the .grec file, but something like this:

              Code:
              .title.xoffset = 2
              .title.yoffset = -2
              I expect that several of these in a row would not cumulate the way DragBy does.

              This observation inspired me to try:

              Code:
              sysuse auto, clear
              scatter trunk weight, title(Test, xoffset(10) yoffset(-10))
              Which works. The xoffset() and yoffset() options are undocumented. Exactly which text elements accept them--axis titles? axis labels?--I don't know. I believe the units are % of the plot or graph region. If I change the -10 to 10 in this example it sends the title outside the viewable area. It can be made visible again with a graphregion(margin(...)) option.

              Comment


              • #8
                Great find with the offset options when specifying the titles! I will definitely be using that.

                Comment

                Working...
                X