Announcement

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

  • Missing grid lines in boxplots

    While playing around with some of the options for box-plots, I discovered under some circumstances, grid lines I request are not displayed. And I cannot see any obvious reason why not. The problem appears to occur when I set the range of y-values too far outside the range that occurs by default.

    I guess the first step is to find out if others can duplicate what I'm seeing. See below for a small demo based on an example in the help system.

    Cheers,
    Bruce

    Code:
    * Example from -help graph box-
    * Using Stata IC 15.1 for Windows
    clear *
    sysuse bplong
    graph box bp, over(when) over(sex) ///
    ytitle("Systolic BP") ///
    title("G1") ///
    ylabel(, labsize(small) angle(horizontal))
    graph rename g1
    
    graph box bp, over(when) over(sex) ///
    ytitle("Systolic BP") ///
    title("G2") ///
    ylabel(120(10)190, labsize(small) angle(horizontal))
    graph rename g2
    
    graph box bp, over(when) over(sex) ///
    ytitle("Systolic BP") ///
    title("G3: Missing gridline at 200") ///
    ylabel(120(10)200, labsize(small) angle(horizontal))
    graph rename g3
    
    graph box bp, over(when) over(sex) ///
    ytitle("Systolic BP") ///
    title("G4: Missing gridlines at 110 & 200") ///
    ylabel(110(10)200, labsize(small) angle(horizontal))
    graph rename g4
    
    graph combine g1 g2 g3 g4, xsize(20) ysize(15)
    graph rename g1234
    
    * Redo graph 4, but add 'grid' sub-option explicitly
    graph box bp, over(when) over(sex) ///
    ytitle("Systolic BP") ///
    title("G4b, Missing gridlines at 110 & 200") ///
    ylabel(110(10)200, grid labsize(small) angle(horizontal))
    graph rename g4b
    * Result:  grid lines still missing at 110 and 200.
    Click image for larger version

Name:	boxplot-missing-gridlines-demo.png
Views:	1
Size:	41.7 KB
ID:	1450948
    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 18.5 (Windows)

  • #2
    I can solve the problem, but I can't explain the logic that requires the solution.

    In your graphs g3 and g4, add the gmin and gmax suboptions to the ylabel option.

    Found this by banging on the Graph Editor until I stumbled across the options that did the trick, then wandered through help files until I found help axis_label_options to tell me what their names are.

    Comment


    • #3
      Thanks William. Yes, that fixes it. But it doesn't make a lot of sense (to me) that it's required.

      For others who may be curious, here is the revised code for the 4th graph, with the gmin and gmax suboptions highlighted.

      Code:
      graph box bp, over(when) over(sex) ///
      ytitle("Systolic BP") ///
      title("G4: Missing gridlines at 110 & 200") ///
      ylabel(110(10)200, gmin gmax labsize(small) angle(horizontal))
      graph rename g4
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 18.5 (Windows)

      Comment


      • #4
        Oh, I agree entirely that it doesn't make sense. I find it interesting that this was the second time this question has been asked in the past two days.

        https://www.statalist.org/forums/for...sing-gridlines

        Perhaps Scott Merryman has some further insight on how he came by his answer to yesterday's version.

        I tend not to believe in coincidences. And further, I don't recall seeing this question before, and the problem seems easy to generate. If nobody has a good explanation, perhaps Stata Technical Services should be shown the problem.

        Comment


        • #5
          A longer look at the description in help axis_label_options tells us this is not a bug but rather a feature. In part, the documentation tells us
          no]gmin and [no]gmax are relevant only if grid is in effect (because grid is the default and nogrid was not specified or because grid was specified). [no]gmin and [no]gmax specify whether grid lines are to be drawn at the minimum and maximum values. Consider

          . scatter yvar xvar, xlabel(0(1)10, grid)

          Clearly the values 0, 1, ..., 10 are to be ticked and labeled, and clearly, grid lines should be drawn at 1, 2, ..., 9; but should grid lines be drawn at 0 and 10? If 0 and 10 are at the edge of the plot region, you probably do not want grid lines there. They will be too close to the axis and border of the graph.

          What you want will differ from graph to graph, so the graph command tries to be smart, meaning that neither gmin nor nogmin (and neither gmax nor nogmax) is the default: The default is for graph to decide which looks best; the options force the decision one way or the other.

          If graph decided to suppress the grids at the extremes and you wanted them, you could type

          . scatter yvar xvar, xlabel(0(1)10, grid gmin gmax)
          With that said, it is not clear to me that Stata's guess about what you want was sensible, so it might still be worth seeing if your example is intended behavior.

          Comment


          • #6
            Perhaps Scott Merryman has some further insight on how he came by his answer to yesterday's version.
            When I was trying to answer yesterday's question I could not originally replicate the problem using 538w as my default scheme, but I could replicate using schemes s2color or sj. Looking for the differences with respect to grid lines I found in the s2color scheme:

            Code:
            yesno draw_major_grid        no
            yesno draw_minor_grid        no
            while 538w has
            Code:
            yesno draw_major_grid        yes
            yesno draw_minor_grid        yes
            From here I found the xaxis label options for gmax and gmin.

            Comment

            Working...
            X