Announcement

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

  • Twoway graph: Grid lines lie on top of frame around plot region - how to avoid that?

    Hello everybody,
    when trying to put a frame around the plot region of a twoway graph, I realized that the y-axis gridlines lie on top of the right side of the frame. So, I the grid lines have a different color (e.g. grey) than the frame (e.g. black), this does not look very nice - see blue circles in example picture below.

    Is there any way to put the gridlines to the background, so they dont overlay the frame around the plotregion?

    If there is a thread on statalist already, please redirect me there, because I couldnt find it.

    Thanks and kind regards,
    Boris

    Code:
      
        twoway (scatter freq z, msymbol(o) mcolor(gs10) mlwidth(thin) msize(medium) ) ///
               (line freq_hat_p1 z if z<0, lcolor(black)) /// p1 pre
               (line freq_hat_p1 z if z>=0, lcolor(black)) /// p1 post
               (line freq_hat_p2 z if z<0, lpat(dash) lcolor(black)) /// p2 pre
               (line freq_hat_p2 z if z>=0, lpat(dash) lcolor(black)) /// p2 post
               , ///
               xline(0, lcolor(black) lstyle(grid)) ///
               xlabel(-72(12)48)  ///
               ylabel(0(10)50) ///
               legend(off) ///
               graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) ///
               ytitle("Number of Observations") xtitle("Month of Arrival")
    Output:
    Attached Files

  • #2
    The option ylabel(,nogextend) prevents drawing of the grid lines in the plot region margin.
    Code:
    sysuse auto
    set scheme s2mono
    scatter mpg weight, plotregion(lcolor(black)) ylabel(,nogextend)
    The width of the plot region margin can be controlled with plotregion(margin()).
    Code:
    scatter mpg weight, plotregion(margin(tiny) lcolor(black)) ylabel(,nogextend)

    Comment


    • #3
      Perfect, that solves the problem. Thanks a lot!

      Comment


      • #4
        Sometimes, this option results in somewhat weird grid lines or data points which are in the outer plot region:

        Code:
        sysuse auto, clear
        
        * With Overlap of Axis and Grid Lines:
        scatter price trunk, scheme(s1mono) xlabel(, grid) ylabel(, grid)
        
        * with option "nogextend"
        scatter price trunk, scheme(s1mono) xlabel(, grid nogextend) ylabel(, grid nogextend)
        
        * with option "nogextend" and smaller plot region margins:
        scatter price trunk, scheme(s1mono) xlabel(, grid nogextend) ylabel(, grid nogextend) plotregion(margin(tiny))

        An alternative is the lalign suboption of plotregion, specifying the "outside" style:

        Code:
        scatter price trunk, scheme(s1mono) xlabel(, grid) ylabel(, grid) plotregion(lalign(outside))
        Last edited by Adam Ansel; 23 Jul 2022, 07:17.

        Comment


        • #5
          Originally posted by Adam Ansel View Post
          Sometimes, this option results in somewhat weird grid lines or data points which are in the outer plot region:

          Code:
          sysuse auto, clear
          
          * With Overlap of Axis and Grid Lines:
          scatter price trunk, scheme(s1mono) xlabel(, grid) ylabel(, grid)
          
          * with option "nogextend"
          scatter price trunk, scheme(s1mono) xlabel(, grid nogextend) ylabel(, grid nogextend)
          
          * with option "nogextend" and smaller plot region margins:
          scatter price trunk, scheme(s1mono) xlabel(, grid nogextend) ylabel(, grid nogextend) plotregion(margin(tiny))

          An alternative is the lalign suboption of plotregion, specifying the "outside" style:

          Code:
          scatter price trunk, scheme(s1mono) xlabel(, grid) ylabel(, grid) plotregion(lalign(outside))

          Hi Adam and everyone,

          I am creating a scheme file for my plots. I want to have the -plotregion(lalign(outside))- option built in the scheme file. However, I fail to find an entry for that in the -help scheme entries- document.

          Any suggestions?

          Kind regards,
          Hall

          Comment

          Working...
          X