Announcement

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

  • yline on only part of x axis

    Hello,

    I am trying to add 4 horizontal lines to my graph, but I do not wish for the lines to go across the entire x axis. For example: I would like a line at 4.5 on the y axis which goes from 0.3-0.55 on the x axis. Then, I would like a line at 7.5 on the y axis that goes from 0.55-0.7 on the x axis. And so on for 2 more lines. I can use yline, but have not found an option that will allow me to specify the length of the line. Is this possible?

    Thank you very much for your help.

    Best,
    Miranda

  • #2
    Code:
    sysuse auto, clear
    scatter mpg weight || scatteri 20 2000 20 3000, recast(line)

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Code:
      sysuse auto, clear
      scatter mpg weight || scatteri 20 2000 20 3000, recast(line)
      Thank you, this works very well. The only issue I have is that the first line (that closest to the y axis) does not hit the y axis. This issue is also shown on this stata page http://www.stata.com/manuals13/g-2gr...ayscatteri.pdf - as you can see, the gray does not touch the y axis. Is it possible to do this? I have tried setting it to 0.2 instead of 0.3 but it just extends the x axis and this occurs even if I set an xscale and xlabel.

      Thank you again for your help.

      Comment


      • #4
        What you are referring to is I think a different issue, which is that plotregion(margin()) does not (usually) default to zero.

        Try the extra option

        Code:
         
        plotregion(margin(zero))
        Otherwise you may need to try harder to pin the x axis down. It may be necessary to specify both xsc() and xla().

        Comment


        • #5
          Originally posted by Nick Cox View Post
          What you are referring to is I think a different issue, which is that plotregion(margin()) does not (usually) default to zero.

          Try the extra option

          Code:
          plotregion(margin(zero))
          Otherwise you may need to try harder to pin the x axis down. It may be necessary to specify both xsc() and xla().

          Code worked perfectly - thank you very much!

          Comment

          Working...
          X