Announcement

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

  • graph hbar specify color of blabel

    I wonder whether it is possible to manipulate the color of a blabel for a specific bar. My use case is that I like to use white color blabel but with some bar colors it is not appropriate and I like to switch to another color for one or two barlabels.
    I know that this is manually possible with the Graph recorder but I like to integrate the manipulation directly into the graph hbar code.

    My code as follows. I deselected a section in which I use two packages from Ben Jann: 1) colorpalette (Jann, B. (2018). Color palettes for Stata graphics. The Stata Journal 18(4): 765-785.) from https://github.com/benjann/palettes/
    2) grstyle ( Jann, B. (2018a). Customizing Stata graphs made easy (part 1). The Stata Journal 18(3): 491-502. Jann, B. (2018b). Customizing Stata graphs made easy (part 2). The Stata Journal 18(4): 786–802.) from https://github.com/benjann/grstyle/ - Both packages are available from SSC as well. If available and of interest you can reselect this part of the script.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int bibid_fak byte psy_neuro
    376 0
    387 0
    123 0
    648 0
    223 0
    330 0
    701 0
    877 0
    186 0
    578 0
    208 1
    306 1
    603 1
    555 1
    148 1
    738 1
    864 1
    745 1
    398 1
    732 1
    801 1
    641 1
    482 1
    116 1
    117 1
    666 1
    372 2
    730 2
    195 2
    210 2
    655 2
    731 2
    434 2
    151 2
    313 2
    573 2
    373 2
    863 2
    471 2
    630 2
    753 2
    754 2
    314 2
    170 2
    188 2
    318 2
    503 2
    815 2
    183 2
    558 3
    250 3
    107 3
    427 3
    419 3
    560 3
     45 3
     21 3
    278 3
     71 3
    530 3
     88 3
    338 3
    236 3
    552 3
    392 3
    433 3
    510 3
    142 3
    553 3
    540 3
    876 3
    243 3
    157 3
     49 3
    776 3
    671 3
      3 3
    202 3
    657 3
     47 3
    274 3
    886 3
    467 3
    207 3
    756 3
    875 3
    580 3
    746 3
     18 3
    452 4
    164 4
     22 4
     33 4
    171 4
    163 4
    end
    label values psy_neuro l_n
    label def l_n 0 "Test 1", modify
    label def l_n 1 "Test 2", modify
    label def l_n 2 "Test 3", modify
    label def l_n 3 "Test 4", modify
    label def l_n 4 "Test 5", modify
    
    
    /*
    colorpalette "112 83 151", intensity(0.2(.2)1) forcergb name(schiefer)
    
    local catn = 5
    
    grstyle init
    foreach n of num 1/`catn' {
        local cp`n' = r(p`n')
        grstyle color p`n' `"`cp`n''"'
    }
    */
    
    graph hbar (count) bibid_fak , over(psy_neuro) stack asyvars ///
                            name(bar_blabtest, replace) ///
                            blabel(bar, pos(inside) format(%4.0fc) size(large) color(white) gap(*.5)) ///
                            legend( pos(6) row(1) )    ///
                            ytitle("") ysc(off)

  • #2
    At the moment my solution is to use a different color that works with black as blabel color.
    So RGB color "176 141 58" works well for me.

    Nonetheless, for other applications it would be great to know if a color of a specific blabel can be manipulated with a command.

    Comment

    Working...
    X