Announcement

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

  • Displaying percentages in stacked bar charts

    Hello, I have been creating some stacked bar charts with the main intention of showing the exact percentages of the variables included in them. To do this, I used the code:
    Code:
    gr bar vote_rd vote_ml if class8 == 4 | class8 == 8, percent stack ///
    over(essround) by(country) blabel(bar, pos(outside))
    However, the results show the numbers overlapping with each other, which makes the results less intuitive. I wanted to ask if there is some way to display this in a manner that is more visually intuitive.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float vote_rd byte(vote_ml class8) float essround double country
    0 0 7 1 2
    0 1 7 1 2
    0 0 . 1 2
    0 . 6 1 2
    1 0 8 1 2
    0 . 7 1 2
    0 1 5 1 2
    0 0 8 1 2
    0 0 5 1 2
    0 0 8 1 2
    0 1 8 1 2
    0 0 6 1 2
    0 1 4 1 2
    1 0 6 1 2
    0 0 5 1 2
    0 0 5 1 2
    0 0 8 1 2
    0 0 8 1 2
    0 1 7 1 2
    1 0 4 1 2
    0 . 4 1 2
    0 0 . 1 2
    0 0 4 1 2
    0 1 1 1 2
    0 0 7 1 2
    0 0 4 1 2
    0 0 7 1 2
    0 . 4 1 2
    1 0 5 1 2
    0 0 7 1 2
    0 . 8 1 2
    0 0 2 1 2
    0 1 7 1 2
    0 . 4 1 2
    1 0 4 1 2
    0 1 4 1 2
    0 0 4 1 2
    0 0 4 1 2
    0 1 8 1 2
    0 1 5 1 2
    1 0 4 1 2
    0 0 8 1 2
    0 1 6 1 2
    0 . 8 1 2
    0 1 8 1 2
    0 0 7 1 2
    1 0 4 1 2
    0 1 6 1 2
    0 0 7 1 2
    0 0 4 1 2
    0 1 4 1 2
    0 1 5 1 2
    0 0 5 1 2
    0 0 8 1 2
    0 0 8 1 2
    0 . 3 1 2
    0 0 4 1 2
    0 0 2 1 2
    0 1 4 1 2
    0 0 1 1 2
    0 0 7 1 2
    0 1 2 1 2
    0 . 8 1 2
    0 1 5 1 2
    0 . 8 1 2
    0 0 8 1 2
    0 0 6 1 2
    0 0 8 1 2
    0 0 6 1 2
    0 . 7 1 2
    0 0 4 1 2
    0 . 4 1 2
    0 1 4 1 2
    0 0 8 1 2
    0 0 7 1 2
    1 0 8 1 2
    0 . 6 1 2
    0 0 1 1 2
    0 1 7 1 2
    0 . 3 1 2
    0 0 5 1 2
    0 0 7 1 2
    0 0 4 1 2
    0 . 4 1 2
    0 0 6 1 2
    0 0 8 1 2
    1 0 8 1 2
    0 0 4 1 2
    0 0 8 1 2
    0 . 8 1 2
    0 0 4 1 2
    0 0 5 1 2
    0 0 8 1 2
    0 1 8 1 2
    0 . 2 1 2
    0 0 2 1 2
    0 1 4 1 2
    0 1 5 1 2
    0 0 1 1 2
    0 0 4 1 2
    end
    label values class8 class8
    label def class8 1 "Self-employed professionals and large employers", modify
    label def class8 2 "Small business owners", modify
    label def class8 3 "Technical (semi-)professionals", modify
    label def class8 4 "Production workers", modify
    label def class8 5 "(Associate) managers", modify
    label def class8 6 "Clerks", modify
    label def class8 7 "Socio-cultural (semi-)professionals", modify
    label def class8 8 "Service workers", modify
    label values country country
    label def country 2 "dk", modify

  • #2
    Your code with your example data yields a graph with only two bars for one country and thus two percentages -- which are legible.

    But in general stacked bar charts can easily be problematic because many bar segments may be short and so numeric text may be squeezed into a very small space. The use of several colours may also interfere.

    If you have 8 classes and several countries it's not hard to imagine such problems.

    These problems have been with us ever since the first stacked bar chart was produced and standard remedies include

    1. Not stacking at all (bars side by side).

    2. Dot charts.

    3. Multiple bar charts as exemplified by tabplot from the Stata Journal. https://www.statalist.org/forums/for...updated-on-ssc is a way into discussion of principles and examples.

    Comment

    Working...
    X