Announcement

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

  • #16
    Here is a similar idea used to give box plot flavour to a quantile plot -- and ideally make the box plot redundant. The median and quartiles are explicit and there is much detail in the tails.

    Click image for larger version

Name:	qbplot1.png
Views:	1
Size:	32.3 KB
ID:	1761833


    Comment


    • #17
      Thank you very much Nick for all these detailed codes and explanations. Much appreciated.

      I have one last question. If I want to include vertical lines on a histogram for specific x values (not quintiles), how would I do that? i.e. something similar to post #11 for the bar graph, but now for a histogram. I tried various combinations of the code you provided for #11, but it did not work. What I could produce so far is something like #9, where the line is hidden behind the graph.

      Here is the data. I want to include lines at several values for x, from 3.4-3.8. Is there also a way of shading this region instead of including lines?

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float(id unemp_des)
        1    .
        2    5
        3  4.2
        4    .
        5    .
        6  5.2
        7    4
        8  4.5
        9  3.9
       10    .
       11    .
       12    .
       13  4.5
       14    .
       15  3.6
       16    .
       17    .
       18    .
       19  5.6
       20  3.2
       21    .
       22  3.6
       23 13.6
       24  2.5
       25    .
       26    .
       27  3.7
       28  3.7
       29    .
       30    4
       31  4.7
       32  3.6
       33  9.1
       34    8
       35  3.4
       36    .
       37  5.7
       38  3.7
       39    5
       40  4.6
       41  5.4
       42  4.7
       43  3.5
       44  8.3
       45  5.2
       46  2.9
       47  2.5
       48  4.3
       49 12.8
       50  5.3
       51  4.8
       52  4.8
       53 16.4
       54  3.6
       55 10.4
       56    .
       57  4.5
       58    .
       59  5.2
       60    .
       61  5.3
       62  3.6
       63  3.5
       64  3.1
       65    .
       66    5
       67    5
       68    5
       69  2.9
       70    4
       71    4
       72  5.8
       73  5.1
       74    .
       75  4.6
       76  3.7
       77  4.8
       78  8.3
       79  4.2
       80    4
       81    .
       82    .
       83    4
       84  3.8
       85  4.7
       86    .
       87    .
       88    .
       89  8.1
       90  4.2
       91    .
       92    4
       93    .
       94  3.7
       95  4.5
       96    .
       97  5.7
       98  3.5
       99  3.3
      100    8
      end

      Comment


      • #18
        We can't explain what you got wrong without seeing any of the wrong code. But it is a rather different problem, or pair of problems, anyway.

        (1) a bar width of 1 and a start of 0 will give bar edges at multiples of 1 so [3.4, 3.8] lies within a bar for [3, 4]

        (2) with the example data that is the second populated bar

        So this code gets you a shaded area:

        Code:
        twoway__histogram_gen unemp_des, width(1) start(0) gen(h x)
        
        local H = h[2]
        
        twoway bar h x, barw(1) lcolor(stc1) fcolor(stc1*0.2) || scatteri  0 3.4 `H'  3.4 `H' 3.8 0 3.8  0, color(stc2) recast(area) legend(off) ytitle(Density) xtitle(unemp_des)
        and this code gets you two lines

        Code:
        local H = h[2] 
        
        twoway bar h x, barw(1) lcolor(stc1) fcolor(stc1*0.2) || scatteri  0 3.4 `H'  3.4 , color(stc2) recast(line) || scatteri 0 3.8 `H' 3.8, color(stc2) recast(line) legend(off) ytitle(Density) xtitle(unemp_des)
        With the full dataset, it might be a different bar. You would need to look at the histogram or a listing of the data.

        If the two lines or the shaded area span two or more bars, it's more complicated, but you've got the principles of shading and adding lines. The most elusive part of the information is the height of the histogram bars.


        Comment


        • #19
          Thank you very much. I will try this approach

          Comment

          Working...
          X