Announcement

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

  • (note: named style Center not found in class barlabelpos, default attributes used)

    Hi Statalists,

    I am trying to produce the attached graph, but with the barlabels in the center of each bar category, instead of on top.

    If I use the command bellow, I get the following two notes:
    • (note: named style Center not found in class barlabelpos, default attributes used)
    • (note: barlabelpos not found in scheme, default attributes used)
    The command to produce the graph:
    Code:
    graph bar (asis) low moderate high, ///
        over(threshold) asyvars percentages stack ///
        bar(1, color(green)) ///
        bar(2, color(orange)) ///
        bar(3, color(red)) ///
        legend(order(1 "Low risk" 2 "Moderate risk" 3 "High risk") rows(1)) graphregion(margin(zero) fcolor(white) lcolor(none) lwidth(none) ifcolor(white) ilcolor(none) ilwidth(none)) plotregion(lcolor(none%0) lwidth(none) ilcolor(none%0) ilwidth(none)) blabel(bar, position(Center) format(%3.1f) justification(center) alignment(middle)) name(lapses, replace)
    The data used is as follows:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str3 threshold float(low moderate high)
    "500" 147 32   7
    "475" 133 34  19
    "450" 118 35  33
    "425"  92 37  57
    "400"  71 44  71
    "375"  28 31 127
    "355"  18 14 154
    end
    Note that my scheme is set to "s2color", and my font (if it matters) to "Avenir-Light".

    How do I get the barlabels to be in the middle of each bar category?

    Thanks so much.

    Rob
    Attached Files

  • #2
    I managed to get what I was looking for. For anyone running into the same problem as me, and want to resolve it, try the below. Note that this may not be the best option, but it worked for me (on Mac, may not work for Windows).
    1. Locate the .scheme file for the scheme you are using. In my case it was s2color.scheme. I located it with spotlight.
    2. Open the file in textedit.
    3. Search for "barlabelpos" in the file (using command + f).
    4. Change the last word of the line which contains "barlabelpos" to "center".
    5. Save the file.
    6. Restart Stata (not sure if this is necessary, but this is what I did).
    7. Run the command again, and it should work now.
    Click image for larger version

Name:	lapse_threshold_status.png
Views:	1
Size:	264.4 KB
ID:	1655618

    Comment


    • #3
      Sorry, but I think it's really bad advice to edit StataCorp-supplied files. here a scheme file. Clone what you like in your own filespace and edit what you like under that name.

      The fix needed for what you want is just position(center) not position(Center).

      I am struggling to read off the numeric values from your graph, even for the moderate category. Here is another take on your problem using tabplot from the Stata Journal.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str3 threshold float(low moderate high)
      "500" 147 32   7
      "475" 133 34  19
      "450" 118 35  33
      "425"  92 37  57
      "400"  71 44  71
      "375"  28 31 127
      "355"  18 14 154
      end
      
      set scheme s2color
      
      graph bar (asis) low moderate high, ///
          over(threshold) asyvars percentages stack ///
          bar(1, color(green)) ///
          bar(2, color(orange)) ///
          bar(3, color(red)) ///
          legend(order(1 "Low risk" 2 "Moderate risk" 3 "High risk") rows(1)) graphregion(margin(zero) fcolor(white) lcolor(none) lwidth(none) ifcolor(white) ilcolor(none) ilwidth(none)) plotregion(lcolor(none%0) lwidth(none) ilcolor(none%0) ilwidth(none)) blabel(bar, position(center) format(%3.1f) justification(center) alignment(middle)) name(lapses, replace)  
          
          
      rename (low moderate high) (whatever#), addnumber
      
      reshape long whatever, i(threshold) j(risk)
      label def risk 1 low 2 moderate 3 high
      label val risk risk
       
      set scheme s1color
      
      tabplot risk threshold [fw=whatever], percent(threshold) showval  yreverse separate(risk) subtitle(% at threshold) ///
      bar3(bcolor(red))  bar2(blcolor(red) bfcolor(red*0.3)) bar1(bcolor(blue*0.6)) name(G1, replace)
      
      egen total = total(whatever), by(threshold)
      gen pc = 100 * whatever / total
      gen toshow = strofreal(whatever) + " (" + strofreal(pc, "%2.1f") + ")"
      
      tabplot risk threshold [fw=whatever], percent(threshold) showval(toshow)  yreverse separate(risk) subtitle(# (%) at threshold) ///
      bar3(bcolor(red))  bar2(blcolor(red) bfcolor(red*0.3)) bar1(bcolor(blue*0.6)) name(G2, replace) xsc(r(0.6 7.4))

      Important detail: red and green do not work well together for many people.

      Click image for larger version

Name:	herbst_G1.png
Views:	1
Size:	18.6 KB
ID:	1655628

      Click image for larger version

Name:	herbat_G2.png
Views:	1
Size:	23.6 KB
ID:	1655629


      Comment


      • #4
        Thanks Nick. Sorry for the bad advice. I would edit my post if I could.

        So this is just a bug in Stata 15.1 then? Because I get that capital C "Center" if I select it through the Bar chart window.

        Good point re the colours I used. Will look into that a bit more.

        I like your tabplot approach. It becomes more clear how the moderate category changes for each threshold. Something I did not really notice from my bar graphs.

        Thanks again!

        Comment


        • #5
          Pleased my post helped. So, the code in #1 is based on selection through the menu in Stata 15.1? I no longer have access to that version to explore.

          Changing company-supplied files has the following disadvantages, which may not be a complete list.

          1. There may be side-effects for other uses.

          2. If you prefer something different, you need to keep changing files whenever there is a new release of Stata, or if a file is updated by StataCorp within releases.

          3. It becomes harder to ensure consistency with what is supposedly the same code.

          4. There isn't any documentation of anything changed unless you write it yourself.
          Last edited by Nick Cox; 22 Mar 2022, 13:45.

          Comment

          Working...
          X