Announcement

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

  • @ all E. Tufte aficionados: How to create a tornado diagram with positive values on both sides of the vertical line?

    Is it possible to create so called tornado diagram with stata? It is a stacked bar chart with a vertical line at the center. I have created such a diagram in Excel (see attachment) but want to redo it with Stata so all my diagrams have the same look in a publication.

    Say you have a variable with four categories (strongy disagree, disagree, agree, strongly agree ). You want to show the stacked percentages of the two groups - person who disagree and persons who agree. The vertical line should represent the value 0%. To both side the values on the x-axis should be increasing to max. 100%, so they are positive. This is the hard part I guess.

    Ideas are highly appreciated.

  • #2
    Code:
    help twoway bar
    explains how to draw population pyramids. The principle is the same in your case. You need some prior calculations of cumulated fractions. See also slideplot from SSC, although the author tells me that he is not especially fond of these graphs.

    Comment


    • #3
      Thanks Nick for pointing me towards slideplot. When I think about it, I saw the command several times already but couldn't recall it.

      Regarding the fondness for tornado diagrams: I know there are pros and cons but in my opinion they convey a good part of the information.

      Comment


      • #4
        If you post the data for your sample graph, anyone interested can play with other representations.

        Comment


        • #5
          My sample graph was not a "sample graph" but a real (and used) one by the research team I work with. Therefore, unfortunately, I cannot post out data here.

          Comment


          • #6
            I don't understand the difficulty. Even if the underlying data are confidential, I am only asking for the percent breakdowns.

            Comment


            • #7
              "...slideplot from SSC, although the author tells me that he is not especially fond of these graphs..." Hmmm; correct me if I'm wrong NJ Cox is is the author.

              Comment


              • #8
                Laurence Lester: You are correct. A plainer way to make the point would be to say that I wrote this command but have come to prefer other approaches to the problem. Wait long enough, and authors can find they have written papers or programs they now think are not their best or even wrong-headed At least that happens to me.

                Comment


                • #9
                  Hi Nick, Hope you didn't take it the wrong way. I wanted attribution because I think it's a very useful, quick to use, routine which I find really handy. Regards
                  Laurence

                  Comment


                  • #10
                    It was just an arch attempt at humour. Sorry if it was puzzling. Later I'll expand on why I prefer other approaches.

                    Comment


                    • #11
                      Hi Nick, you are right, I can present the row-percent breakdowns. So here we go:

                      HTML Code:
                      
                           16-24 |     40,83      41,00      14,23       3,94 |    100,00
                           25-34 |     43,57      44,09       9,39       2,95 |    100,00
                           35-44 |     46,19      43,09       8,24       2,47 |    100,00
                           45-54 |     45,35      43,97       8,37       2,32 |    100,00
                           55-64 |     41,10      44,44      11,10       3,36 |    100,00
                           65-74 |     35,07      44,30      15,67       4,97 |    100,00
                           ab 75 |     26,04      41,90      23,03       9,03 |    100,00
                      -----------+--------------------------------------------+----------
                           Total |     41,08      43,52      11,73       3,66 |    100,00

                      Comment


                      • #12
                        Thanks. I will take this as sandbox. I've not looked at slideplot for some years, so it seemed more fun to re-create something using graph hbar directly. This gets some way towards your kind of graph. To add extra text, you would need to use text() options or switch to twoway rbar.

                        I also show an alternative with tabplot (SSC). I tend to prefer it as allowing a hybrid of graph and table and as showing the fine structure (including zeros and very small amounts) more explicitly.

                        I haven't tried translating your category labels.

                        Code:
                         
                        set scheme s1color 
                        clear 
                        input str5 age_class p1 p2 p3 p4 
                        "16-24" 40.83 41.00 14.23 3.94 
                        "25-34" 43.57 44.09 9.39 2.95 
                        "35-44" 46.19 43.09 8.24 2.47 
                        "45-54" 45.35 43.97 8.37 2.32 
                        "55-64" 41.10 44.44 11.10 3.36 
                        "65-74" 35.07 44.30 15.67 4.97 
                        "75+" 26.04 41.90 23.03 9.03 
                        end
                        label var age_class "age class" 
                        gen P3 = -p3
                        gen P4 = -p4
                        label var p1 "++"
                        label var p2 "+"
                        label var P3 "-"
                        label var P4 "--"
                        local blc blcolor(black)
                        local lw lw(*0.1)
                        graph hbar (asis) P3 P4 p2 p1, over(age_class, descending) stack ///
                        bar(1, `lw' `blc' bfcolor(gs6))   ///
                        bar(2, `lw' `blc' bfcolor(gs1))   ///
                        bar(3, `lw' `blc' bfcolor(gs11))  ///
                        bar(4, `lw' `blc' bfcolor(white)) ///
                        yli(0, lw(medium) lc(black)) yla(-100 "100%" -50 "50%" 0 50 "50%" 100 "100%") ///
                        legend(order(2 1 3 4) row(1))
                        
                        graph export slide1.png, as(png) replace 
                        
                        reshape long p , i(age_class) j(answer) 
                        label def answer 1 "++" 2 "+" 3 "-" 4 "--" 
                        label val answer answer 
                        rename p percent
                        tabplot answer age_class [iw=p], showval(format("%3.2f")) bfcolor(white) blcolor(black) 
                        
                        graph export slide2.png, as(png) replace
                        Click image for larger version

Name:	slide1.png
Views:	1
Size:	11.5 KB
ID:	1295101
                        Click image for larger version

Name:	slide2.png
Views:	1
Size:	14.7 KB
ID:	1295102

                        Comment


                        • #13
                          Nick, now I am in trouble because I have to decide which one to take. I agree with you that the hybrid-plot created with tabplot has more detailed information but it also needs a little more attention, in my humble opinion, to see it. Readers without "the statistical eye" might appreciate the upper plot more.

                          Comment


                          • #14
                            It's your choice. Note that you can tune the rounding of data (nearest %, e.g.) and also play with the details of bar geometry.

                            Code:
                             
                            set scheme s1color 
                            clear 
                            input str5 age_class p1 p2 p3 p4 
                            "16-24" 40.83 41.00 14.23 3.94 
                            "25-34" 43.57 44.09 9.39 2.95 
                            "35-44" 46.19 43.09 8.24 2.47 
                            "45-54" 45.35 43.97 8.37 2.32 
                            "55-64" 41.10 44.44 11.10 3.36 
                            "65-74" 35.07 44.30 15.67 4.97 
                            "75+" 26.04 41.90 23.03 9.03 
                            end
                            label var age_class "age class" 
                            
                            reshape long p , i(age_class) j(answer) 
                            label def answer 1 "++" 2 "+" 3 "-" 4 "--" 
                            label val answer answer 
                            rename p percent
                            tabplot answer age_class [iw=p], showval(format("%1.0f")) barw(0.9)  aspect(1) height(0.6) bfcolor(white) blcolor(black) 
                            
                            graph export slide3.png, as(png) replace
                            Click image for larger version

Name:	slide3.png
Views:	1
Size:	12.0 KB
ID:	1295175

                            Comment


                            • #15
                              Thanks to Nick for these ideas (need to change [iw=p] to [iw=percent] in #12 & #14?)
                              Last edited by Laurence Lester; 21 May 2015, 18:18.

                              Comment

                              Working...
                              X