Announcement

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

  • Adding % to stacked bar chart

    Dear statalisters,

    is there a way to add %-signs (by code) to my stacked bar chart?

    here is the code for data preperation and graph:


    foreach var of varlist (Q603_1_N - Q603_7_N) {
    recode `var' 3=1 1=2 6=3 2=4 5=5 4=6
    }

    mvdecode Q603_1_N - Q603_7_N, mv (6=.a)

    foreach var of varlist (Q603_1_N - Q603_7_N) {
    label define `var' 1 "gut" 2 "eher gut" 3 "teils, teils" ///
    4 "eher schlecht" 5 "schlecht", modify
    }


    * Vorbereitung für Grafik
    clonevar ta1= Q603_1_N
    clonevar ta2= Q603_2_N
    clonevar ta3= Q603_3_N
    clonevar ta4= Q603_4_N
    clonevar ta5= Q603_5_N
    clonevar ta6= Q603_6_N
    clonevar ta7= Q603_7_N

    local ta1: var lab ta1
    dis "`ta1`"
    foreach var of varlist _all {
    local `var`: var lab `var`
    }


    gen id = _n
    reshape long ta, i(id)
    rename ta score
    *-------------------------------------------------------------------------------------------------------------------------
    set scheme prognos
    graph set window fontface "Franklin Gothic Book"
    graph hbar (percent) if BundeslandAdressinformation== "Nordrhein-Westfalen" , over (score) over(_j, relabel ///
    (1 "Werdende Eltern" 2 "Paarfamilien (Familien mit zwei Elternteilen)" 3 "Alleinerziehende (Familien mit einem Elternteil)" ///
    4 "Familien mit Migrationshintergrund" 5 "Personen in Trennung/Scheidung" 6 "Sozial schwache Familien" ///
    7 "Familien mit wenig Internetkenntnissen")) asyvars percentage stack ///
    blabel(bar, pos(center) size(2.5) color(white) format(%2.0f)) ytitle("") ylabel( 0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%") ///
    title("") legend(pos(bottom) cols(5)) name(graph1, replace) xsize(7)


    Thanks a lot! Beste regards, Tim

  • #2
    here´s the graph btw
    Click image for larger version

Name:	stacked_bar.png
Views:	1
Size:	37.6 KB
ID:	1686655

    Comment


    • #3
      I don't think this will be easy to do, but I would like to ask: why do you want to do this? To me, putting percentage signs everywhere would only create visual clutter. It is already clear from the horizontal axis that the numbers are in percentage terms.

      Comment


      • #4
        Same issues in https://www.statalist.org/forums/for...s-in-bar-graph

        One-sentence summary: this is easier with some flavour of graph twoway than it is with graph bar or graph hbar.

        Comment

        Working...
        X