Announcement

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

  • blabel: showing only cumulative value for each bar

    Dear all,
    I am running a code for a stacked graph bar for which I would like to show the data values above the bars. I used the option blabel(total). Is there a way to make only the total cumulative value of of each bar show up (sum of both stacked bars for each xlabel)? I am not interested in the data value labels for the dark blue bars.

    The code I used to get the graph below was:
    Code:
    graph bar percap_gov percap_pri if year==2015 & selection==1, stack ///
    over(location, label(angle(90) labsize(small)) sort(percap_total) descending) ///
    ytitle("") yscale(off) blabel(total, orientation(vertical) size(small) format(%9.0f)) nofill ///
    ysize(9) xsize(18) graphregion(color(white)) ylab(, nogrid) ///
    legend(label(1 "Government") label(2 "Private Sector + DAH") pos(1) col(1) ring(0) size(small) region(c(none))) ///
    bar(1, bcolor(blue*1.3)) bar(2, bcolor(blue*0.1))
    Click image for larger version

Name:	graf_percap_stack.png
Views:	1
Size:	78.1 KB
ID:	1446559

  • #2
    I believe you will have to construct the graph using twoway bar and scatter. For example:

    Code:
    use http://www.stata-press.com/data/r15/citytemp,clear
    
    //original graph
    graph bar (mean) tempjuly tempjan, over(region) stack blabel(total, orientation(vertical)  /// 
      size(small) ) name(gr1,replace) 
      
    collapse (mean) tempjul tempjan, by(region)
    gen sumtemp = tempjul + tempjan
    
    twoway bar tempjul region, base(0)   barw(0.5) fin(50) ylabel(0(50)150) xtitle("")  /// 
     || rbar  tempjul sumtemp region , barw(0.5) xla(1/4, noticks valuelabel)  fin(50) /// 
      || scatter sumtemp region, ms(none) mla(sumtemp) mlabpos(12) mlabangle(vertical) mlabgap(7) /// 
      legend(order( 1 "mean of tempjuly"  2 "mean of tempjan")) name(gr2,replace)

    Comment

    Working...
    X