Announcement

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

  • Adding diagonal line to a twoway graph when axes have very different ranges

    Dear StataList,
    I am trying to add a diagonal line to a twoway graph in which the x and y axes have very different ranges. For example,
    Code:
    sysuse auto, clear
    twoway (scatter price length)


    When I use the function y=x option with the y axis as the range value, the x axis is extended and the line begins at the lowest observed value on the y axis:
    Code:
    sysuse auto, clear
    twoway (scatter price length) (function y=x, range(price))


    Switching away from function to line produces essentially the same graph:
    Code:
    sysuse auto, clear
    twoway (scatter price length) (line price price, sort)


    Is there a way to keep both axes as they originally are but add a diagonal line that extends from (0,0) to the upper right quadrant?

    Thank you.
    Last edited by James Sanders; 01 Nov 2017, 10:42.

  • #2
    Replace price by length in your second example.
    Code:
    sysuse auto, clear
    twoway (scatter price length) (function y=x, range(length))
    Edit: I misunderstood your question. I think you want something like this:
    Code:
    twoway (scatter price length) (scatteri 0 140 16000 240, connect(l) msymbol(i))
    Last edited by Friedrich Huebler; 01 Nov 2017, 10:55.

    Comment


    • #3
      Thank you for your help Friedrich.

      Comment

      Working...
      X