Announcement

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

  • Way to programmatically draw lines on a two-way figure

    Hello
    I am trying to figure out if there is a way to draw a line from point (X1,Y1) to point (X2,Y2) when creating a two-way graph. I know I can make lines at a specific X or Y coordinate, but these lines continue the length of the graph window.
    Is this possible without manually doing it with the graph editor?

    thanks!

    hp

  • #2
    Here's a toy example of how to do this:
    Code:
    clear*
    sysuse auto
    gen x = 15 in 1
    replace x = 30 in 2
    gen y = 4500 in 1
    replace y = 12000 in 2
    
    graph twoway (scatter price mpg) (line y x)

    Comment


    • #3
      Code:
      help tw scatteri
      Code:
      sysuse auto, clear
      tw scatter mpg weight||scatteri 30 2500 30 4000, recast(line)  lw(vthick) leg(off)
      Res.:

      Click image for larger version

Name:	Graph.png
Views:	1
Size:	42.8 KB
ID:	1770484

      Last edited by Andrew Musau; 08 Jan 2025, 15:04.

      Comment


      • #4
        amazing! thanks to both of you for the help!

        Comment


        • #5
          See also https://journals.sagepub.com/doi/pdf...6867X241276116 for a miniature review of adding extra lines to graphs.

          Comment

          Working...
          X