Announcement

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

  • Module for stacked area graphs

    Hi,

    For my research I spend a lot of time looking at trends in the distribution of categorical variables as a function of time, career length, and so forth. Since as far as I can tell STATA doesn't have native capability for stacked area graphs, I created a module called stackedcount that would produce plots with the frequencies of the categories of a variable stacked on the vertical axis against a discrete numeric variable like year, age, career length on the horizontal axis. The initial inspiration was a 2018 post in a thread on stacked area graphs by Andrew Musau.

    The module is available via ssc install stackedcount. It includes a sthelp file.

    For more details, I have a post about it at my blog that includes some sample code and the resulting figures.

    Here is a sample:



    stacked_count chushen year if xuhao < 20000 & !qiren & ming != "" & year >= 1830 & !central & !fangkeben_only & !irregular & !ignore & !new_in_1911, xtitle("Year") xtick(1830(5)1910) xmtick(1830(1)1910) xlabel(1830(10)1910) ytitle("Records of officials") ylabel(0(2000)8000,labsize(small)) ymtick(0(1000)8000) legend(cols(4) size(vsmall))

    I hope others find this useful.

    I have a companion module called stackedpercent that I will submit to SSC in a little bit.

  • #2
    Thanks for the mention Cameron Campbell. Awesome!

    Comment


    • #3
      Hello, thanks for uploading this package.
      Just wondering if it is possible to make a smooth line in the stacked area graph rather than bars next to another.

      Comment


      • #4
        #4 See the link in #1 https://www.statalist.org/forums/for...cked-area-plot

        Comment


        • #5
          Hi Nick,
          Thanks for your quick reply.
          I was trying to create a chart to describe the age proportion changes for cases along with the time in days. It is tricky to create cumulative categories for age groups. I will work on that.

          Comment


          • #6
            Originally posted by Guosong Wu View Post
            Hello, thanks for uploading this package.
            Just wondering if it is possible to make a smooth line in the stacked area graph rather than bars next to another.
            I would need to go back and look but I think that could be done by removing some code. In some early version I simply connected the heights at different points in time. However that led to undesirable behavior in situations when an edition of the 縉紳錄 was missing. Then the line would angle down to zero and then angle back up in the next quarter for which an edition was available. I then added the code so that it would plot a horizontal line to the beginning of the next interval, thereby producing bars.

            Comment


            • #7
              Cameron Campbell It's your module with a clear selling point, showing gaps honestly. If you can generalise it so that the default is just what it is, that would be fine for many users.

              You make it very clear that your program is for stacking the frequencies of categories of one variable against a second variable. Predictably, despite that clarity, there is going to be some puzzlement over that or some pressure to support quite different applications, stacking the values of two or more numeric variables or even stacking the values of different panels.

              Your choice!

              On a different level, I am sceptical myself about stacked designs, but this thread is not the best place to take that forward.

              Comment


              • #8
                Thanks!

                Comment


                • #9
                  I updated my discussion of the module here: https://camerondcampbell.blog/stacke...aphs-in-stata/

                  I added some explanation of the handling of the x values including the display of cumulative values of y as bars rather than as values connected by diagonal lines.

                  I also added some discussion of how the xrange option allows for the 'filling in' of missing values of x so that they will be shown as empty rather than having values carried forward from the most recent available value of x. If xrange is not specified, values will be carried forward from the most recent specified value of x.

                  I'll update the help file with this added detail as well, after allowing some time to see if there are other comments.

                  Comment


                  • #10
                    Dear Cameron,

                    I am using your "stackedpercent"-command (which I like a lot) and was wondering, how I can (i) change the colours of the different categories and (ii) get rid of the darker line that separates one category from the next one?

                    My y-variable has 10 different categories and I would like to change the colour for each of them.

                    This is my current code:

                    Code:
                    stackedpercent y x, scheme(tab2)
                    Thanks a lot!
                    Sandra

                    Comment


                    • #11
                      Cameron Campbell visited Statallist a few times in 2020. https://camerondcampbell.blog/contact/ gives a way to contact him directly if he doesn't answer.

                      For another take on stacking areas see #4 within https://www.statalist.org/forums/for...cked-area-plot

                      Comment


                      • #12
                        Let me look into this. It should be possible if I add to the options that are passed through, but I need to check. It might take me a few days.


                        Originally posted by Sandra Span View Post
                        Dear Cameron,

                        I am using your "stackedpercent"-command (which I like a lot) and was wondering, how I can (i) change the colours of the different categories and (ii) get rid of the darker line that separates one category from the next one?

                        My y-variable has 10 different categories and I would like to change the colour for each of them.

                        This is my current code:

                        Code:
                        stackedpercent y x, scheme(tab2)
                        Thanks a lot!
                        Sandra

                        Comment


                        • #13
                          Thank you very much Cameron!

                          Comment

                          Working...
                          X