Announcement

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

  • How to adapt the y-axis in a two-way graph?

    Dear Stata Users,

    I am facing some difficulties when changing the range of values that should be displayed on the y-axis in my two-way plot. I want the y-axis to range from -0.2 to 0.2 but more zoomed in so that -0.2 is at the intersection of y and x axis where one would usually have the zero. In the example graph the 0.2 starts half in the graph and I want the range to be more zoomed in.

    Do you have any idea on how I can modify my code?

    Code:
    twoway (scatter residual time, msy(x)) (line av_residual time, yline(0)) yscale(r(-0.2 0.2)) yla(-0.2(0.2)0.2))
    Attached Files

  • #2
    The -yscale()- option serves only to tell Stata which points on the axis to label, and what the labels should be. The -yscale(r())- option allows you to expand, but not shrink the range of the scale. The logic behind this design is that Stata will not omit any data. Stata will choose the range of the axis to be convenient round numbers that include the full range of values to be plotted. So if you want to restrict the range of an axis, you have to restrict the range of the data accordingly. Try
    Code:
    twoway (scatter residual time if inrange(residual, -0.2, 0.2), msy(x)) (line av_residual time if inrange(av_residual, -0.2, 0.2), yline(0)) yscale(r(-0.2 0.2)) yla(-0.2(0.2)0.2))
    Last edited by Clyde Schechter; 13 Mar 2023, 11:55.

    Comment

    Working...
    X