Announcement

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

  • Adding horizontal and vertical lines to functions

    Dear all,

    I have a small problem and I can't find it documented anywhere, but is it possible in Stata 13.1 to draw a line from a specific tick to the x-axis and y-axis?

    In order to clarify what I would like I've constructed the following example:
    Code:
    graph twoway function y=x^2
    Now what I would like is at tick (2, 4) to have a line drawn from (2, 0) to (2, 4) (i.e. a vertical line from the x-axis to the tick) and a line drawn from (0, 4) to (2, 4) (i.e. a horizontal line from the y-axis to the tick.

    Yours sincerely,

    Wen Jun Jie

  • #2
    Two possibilities:

    Code:
    graph twoway function y=x^2 , range(0 3) xline(2) yline(4)
    
    twoway (function y=x^2, range(0 3) dropline(2)) (function y=4, range(0 2))

    Comment


    • #3
      The first solution (in which you use xline and yline), I've considered, but it will also draw lines past the tick. This is not exactly what I want.
      The second solution looks really good and promising, thanks!

      I was wondering whether I could automate the calculation of the y-value. In my case the function is rather simple, but I can imagine that if you have a more compllicated function, you wouldn't want to calculate it.

      Comment

      Working...
      X