Announcement

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

  • Removing "0" Labels in graph hbar blabel

    Hello,

    I am making a hbar plot that has shows the percentage of counts across 7 different variables (e.g. vfh_3mo_level_0, vfh_3mo_level_1, etc) that have values of either "1" or missing ("."), over a variable that has two groups to which patients were assigned to. The resulting plot is excellent, however, the blabel option results in 0's in between certain stacked bars (please see plot).

    Can you advise how I can remove these 0's in the bar labels?

    Thank you!

    Code:
    graph hbar (count) ///
            vfh_3mo_level_0 ///
            vfh_3mo_level_1 ///
            vfh_3mo_level_2 ///
            vfh_3mo_level_3 ///
            vfh_3mo_level_4 ///
            vfh_3mo_level_11 ///
            vfh_3mo_level_14 ///
        , stack percent ///
        over(group) asyvars ///    
            nofill graphregion(color(white)) ///
            legend(order( ///
                1 "A" ///
                2 "B" ///
                3 "C" ///
                4 "D" ///
                5 "E" ///
                6 "F" ///
                7 "G" )) ///
                blabel(bar, color(white) position(center) format(%2.0f)) ///
                ytitle("Percentage") ///
            bar(1, fcolor(red*0.1) lwidth(none)) ///
                bar(2, fcolor(red*0.5) lwidth(none)) ///
                bar(3, fcolor(red*1.0) lwidth(none)) ///
                bar(4, fcolor(red*1.5) lwidth(none)) ///
                bar(5, fcolor(red*2) lwidth(none)) ///
                bar(6, fcolor(red*2.5) lwidth(none)) ///
                bar(7, fcolor(red*8) lwidth(none))
    Here is the resulting plot:
    Click image for larger version

Name:	Hbar Plot with 0s.jpg
Views:	1
Size:	36.4 KB
ID:	1741633


  • #2
    At a guess, you are being shown zeros for categories that don't occur.

    I would use tabplot here from the Stata Journal. See e.g. https://www.statalist.org/forums/for...updated-on-ssc

    Comment


    • #3
      Thank you for your prompt support Nick! I will explore tabplot and attempt to remake the plot that way instead.

      Comment


      • #4
        Dear Nick, I wanted to update that tabplot worked excellently for my purposes, and much better than graph hbar. Thank you for the prompt support! (Of note, instead of using 7 different variables in the tabplot, as I had using graph hbar, instead I created one variable that combined the seven different variables. Worked excellently.)
        Last edited by Nathan Yu; 01 Feb 2024, 20:40.

        Comment


        • #5
          Thanks much for update and closure!

          Comment

          Working...
          X