Announcement

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

  • Stacked bar chart showing changing proportions in a population over time.

    Hello all. Sorry for the novice query but I have struggled with this for the best part of today. I am trying to visualise whether or not a score (on a scale 0-10) has changed over time amongst patients recruited to a study. I do not have multiple data points for each patient and so I am trying to see whether the population of patients recruited has changed over time.

    In my data (below), "amts" is the score and "timesincelaunch" is the time period. As the median is "9" throughout the dataset, I can't really plot medians on a line graph and would like to create a stacked bar chart instead, i.e. showing the proportion of patients with each score (10, 9, 8) at each time point. I have tried
    Code:
    graph bar amts, over(timesincelaunch) stack"
    and using "collapse" but neither approach led to anything meaningful.

    Can anyone suggest a way forward?


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte amts float timesincelaunch
    10  0
     1  1
    10  6
    10  7
     9  9
    10  9
     6  9
     4 10
     8 10
    10 10
    end

  • #2
    I wouldn't use a stacked bar chart here at all. It's often a poor design and with (if I understand this correctly) 11 distinct values you need a legend and impose a burden of scanning back and forth on the reader. Consider instead

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte amts float timesincelaunch
    10  0
     1  1
    10  6
    10  7
     9  9
    10  9
     6  9
     4 10
     8 10
    10 10
    end
    
    tabplot amts timesincelaunch, yasis xasis horizontal 
    
    histogram amts, by(timesincelaunch, row(1)) horizontal discrete freq bfcolor(ltblue) blcolor(blue) yla(, ang(h))
    Here for tabplot see e.g.


    SJ-16-2 gr0066 . . . . . . Speaking Stata: Multiple bar charts in table form
    (help tabplot if installed) . . . . . . . . . . . . . . . . N. J. Cox
    Q2/16 SJ 16(2):491--510
    provides multiple bar charts in table form representing
    contingency tables for one, two, or three categorical variables

    or search for threads within the forum.


    Comment


    • #3
      Thank you very much - these solutions work much better than the one I was working towards.

      Comment

      Working...
      X