Announcement

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

  • Labeling edges of box (and whisker) plots: 25% median, 75%. How?

    I am analyzing an ordinate set of text level reading scores. I am using the median and the interquartile range (IQR) for three administrations of the assessment: fall, winter, and spring. I want to accompany the data with box-and-whiskers plots (graph box) and want to indicate what score marks the 25th percentile, the median, and the 75th percentile. The analysis (for 76 elementary schools) is for administrators and teachers. I am flummoxed at labeling the left and right corners of the box and the median. I've tried following the options and using the graph editor. No luck. I am using Stata 12. Any pointers, specific directions?

  • #2
    You don't show any code that you tried (see FAQ Advice #12).

    On the whole, the more you want to depart from graph box, the more you need a different approach.

    Code:
    stripplot
    (SSC) offers one possibility.

    Code:
    sysuse auto, clear
    set scheme s1color
    egen median = median(mpg), by(foreign)
    egen loq = pctile(mpg), by(foreign) p(25)
    egen upq = pctile(mpg) , by(foreign) p(75)
    gen foreign2 = foreign + 0.1
    stripplot mpg, over(foreign) box(barw(0.2)) vertical ///
    addplot(scatter median loq upq foreign2, ms(none ..) ///
    mla(median loq upq) mlabcolor(blue ..)) xsc(r(. 1.2)) xla(, noticks)
    Click image for larger version

Name:	anotherboxplot.png
Views:	1
Size:	10.0 KB
ID:	1358406


    See also

    http://www.stata-journal.com/article...article=gr0039
    http://www.stata-journal.com/article...ticle=gr0039_1
    Last edited by Nick Cox; 28 Sep 2016, 16:55.

    Comment


    • #3
      Here is another variant. I like the quantile-box plots used by Emanuel Parzen. I also made the marker labels a little larger and shifted them away from the boxes.

      Code:
      sysuse auto, clear
      set scheme s1color
      egen median = median(mpg), by(foreign)
      egen loq = pctile(mpg), by(foreign) p(25)
      egen upq = pctile(mpg) , by(foreign) p(75)
      gen foreign2 = foreign + 0.15
      
      stripplot mpg, over(foreign) box(barw(0.2)) centre cumul ///
      cumprob vertical height(0.4) ///
      addplot(scatter median loq upq foreign2, ms(none ..) ///
      mla(median loq upq) mlabcolor(blue ..) mlabsize(*1.2 ..)) xsc(r(. 1.2)) xla(, noticks)
      Click image for larger version

Name:	anotherbox2.png
Views:	1
Size:	10.6 KB
ID:	1358433

      Comment


      • #4
        Thanks, Nick Cox. I had gotten called away to do some different number crunching and have just returned to this project. I will post my attempts and try your suggestions hopefully later today.

        Comment


        • #5
          Yet more annotation. Perhaps over the top, but some small tricks are shown. The means are shown in orange and the sample sizes too.

          Code:
          sysuse auto, clear
          set scheme s1color
          
          egen median = median(mpg), by(foreign)
          egen loq = pctile(mpg), by(foreign) p(25)
          egen upq = pctile(mpg) , by(foreign) p(75)
          egen mean = mean(mpg), by(foreign) 
          egen min = min(mpg)
          egen n = count(mpg), by(foreign) 
          
          gen shown = "{it:n} = " + string(n) 
          gen foreign2 = foreign + 0.15
          gen foreign3 = foreign - 0.15 
          
          gen showmean = string(mean, "%2.1f") 
          
          stripplot mpg, over(foreign) box(barw(0.2)) centre cumul ///
          cumprob vertical height(0.4) ///
          addplot(scatter median loq upq foreign2, ms(none ..) ///
          mla(median loq upq) mlabcolor(blue ..) mlabsize(*1.2 ..) || ///
          scatter mean foreign3, ms(none) mla(showmean) mlabcolor(orange) mlabsize(*1.2) mlabpos(9) || ///
          scatter min foreign, ms(none) mla(shown) mlabcolor(black) mlabsize(*1.2) mlabpos(6)) ///
          xsc(r(. 1.2)) xla(, noticks)
          Click image for larger version

Name:	anotherboxplotwithmorestuff.png
Views:	1
Size:	27.0 KB
ID:	1358771

          Comment

          Working...
          X