Announcement

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

  • Placement and subtitle of bar graphs using by_options

    Fellow Stata users,
    I am using Stata version 15.1. I am trying to reorder the placement and change the subtitle of a graph generated using
    Code:
    graph bar, by
    The pertinent code for my question is currently written:
    Code:
    #delimit ;
    graph bar dchome mobimp improved_home if ptminutes_cat!=1 & dchome!=. & servicecat!=6, 
        over(freqcat, relabel(1 "1-2" 2 ">2-4" 3 ">4-7" 4 ">7"))
        by(servicecat, total note(""))
    ;
    This works nicely in returning the following plot:
    Click image for larger version

Name:	Figure1_BarOutcomes.png
Views:	1
Size:	73.1 KB
ID:	1616814


    I have two adjustments I wish to make. First, to reorder the placement of the graphs so that the "Total" graph is in position 1. Second, to rename the "Total" graph with a new subtitle, "All Patients". Are there by_options that could accomplish either of both of these?

    Thank you.


  • #2
    You will want to generate the total category yourself and assign it the lowest category. Otherwise, I am not aware of an explicit option to achieve what you want in gr bar.

    Code:
    sysuse auto, clear
    set scheme s1color
    gr bar mpg turn trunk, by(rep78, total leg(off)) saving(gr1, replace) 
    preserve
    expand 2
    *REP78 IS CODED 1-5. ASSIGN TOTAL CAT VALUE 0
    replace rep78=0 if _n>_N/2
    lab def rep78 0 "whatever"
    lab values rep78 rep78
    gr bar mpg turn trunk, by(rep78, leg(off)) saving(gr2, replace)
    gr combine gr1.gph gr2.gph
    restore
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	60.3 KB
ID:	1616834


    Comment


    • #3
      Andrew Musau - That was a fantastic suggestion and worked beautifully! Thank you!

      Comment

      Working...
      X