Announcement

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

  • Centering the origin of the Cartesian plane in –twoway– graphs

    Does anyone have a favorite method for doing this?

    When I need to produce a graph where (x,y)=(0,0) is in the center of the graph I use a brute force approach like that used to generate the graph created by this do-file.

    I suspect there are more elegant ways to do this, however.
    Code:
    cap preserve
    cap drop _all
    set obs 25
    gen y=runiform()-.5
    gen x=runiform()-.5
    scatter y x, xlab(0) ylab(0) xsc(r(-.5 .5) noline) ysc(r(-.5 .5) noline) ///
    xline(0) yline(0) yti(,orient(horiz)) ylab(,angle(360))
    cap restore

  • #2
    I would add aspect(1)

    Comment


    • #3
      The tension between statistical logic and graphical taste is delicate. Stata follows a general principle that data elements should not be obscured by other elements such as axes or annotation of any kind. So it won't put axes (meaning y = 0, x = 0) in the data region when negative values are present.

      That said, people interested in this may care to experiment:

      1. You can make the axes as unobtrusive as possible -- while remaining visible -- by choosing a subdued colour and thinner lines.

      2. You could flip things round and plot white axis lines against a light non-white backdrop. There is then a long slippery slope towards emulating what is often declared "beautiful" as a result of ggplot2 in R.

      Code:
      clear 
      set obs 25
      gen y=runiform()-.5
      gen x=runiform()-.5
      set scheme s1color
      scatter y x, xlab(0) ylab(0) xsc(r(-.5 .5) noline) ysc(r(-.5 .5) noline) ///
      xline(0, lc(gs8) lw(vthin)) yline(0, lc(gs8) lw(vthin))
      
      scatter y x, xlab(0) ylab(0) xsc(r(-.5 .5) noline) ysc(r(-.5 .5) noline) ///
      xline(0, lc(white)) yline(0, lc(white)) yti(,orient(horiz)) ylab(,angle(360)) plotregion(color(gs14))

      Comment


      • #4
        Nick: Thanks for your ideas on this. I just tweeted this thread; hopefully I've given you adequate credit. https://twitter.com/JohnMullahy/stat...627188736?s=20

        Comment


        • #5
          John:
          when I came across your post earlier today I thought you were about to draw a cost-effectiveness plane as per William Black's article (https://pubmed.ncbi.nlm.nih.gov/2115096)!!
          Kind regards,
          Carlo
          (StataNow 18.5)

          Comment


          • #6
            Thanks Carlo. The C/E plane would certainly be one reason to consider appropriateness of the axes' placement. Thanks for pointing out this article to me.

            Comment

            Working...
            X