Announcement

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

  • Cut axis without excluding data points

    Hi

    I am working on a twoway plot where one data point is quite large compared to the rest. However, I do not want to exclude this point, but it would be nice to adjust the x-scale to range -.03 to .03 below, i.e. start from -.03 and not -.06.

    In the graph below I have tried to illustrate what I am interested in: a graph starting at the blue line, then an arrow can indicate that the lowest data point here extends beyond -.03. It seems like -xscale(r())- does not cut the x-axis if there are data points outside the specified range.
    Click image for larger version

Name:	xscale.png
Views:	1
Size:	78.1 KB
ID:	1615745


    Here is the code used to create the graph:
    Code:
    twoway (scatter y x, ///
    xline(0) ///
    xscale(r(-0.03(0.01)0.03)) ///
    xlabel(-0.03(0.01)0.03) ///
    (dropline x y base(0) horizontal)

  • #2
    I do not want to exclude this point, but it would be nice to adjust the x-scale to range -.03 to .03 below, i.e. start from -.03 and not -.06.
    Well, this is just excluding the point. You cannot truncate the axis in twoway graphs, you need to explicitly exclude that observation using the -if- qualifier. Then you can extend the axis when plotting and include the line with an arrow (or include an invisible marker at (0 -0.03)).

    Comment


    • #3
      See also https://www.stata.com/support/faqs/g.../scale-breaks/

      Someone commented somewhere (Twitter?) that this FAQ seems designed to make them feel guilty about wanting a scale break, which I won't fully deny. Still, there is some guidance in the FAQ.

      A more exotic alternative is a cube root scale. Cube root, meaning concretely sign(x) * abs(x)^(1/3) will pull the outlier in.

      Comment

      Working...
      X