Announcement

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

  • donut charts

    hi guys!

    i was wondering whether stata supports pie charts of the donut variety - after a quick search I came to conclude that the answer is no, but I might have missed something.

    thanks,
    natalia

  • #2
    They are just about programmable but would be hard work. Best avoided any way.

    Comment


    • #3
      I guess I don't see the point of donut charts at all. (One recent book lumped "donut charts" and "pie charts" together as "dessert graphics".)

      Here is one sandbox for play.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str13 continent byte name_and_value float value str19 str_name_and_value
      "Europe"        1    7 "Europe 7.0"        
      "Asia"          2 29.5 "Asia 29.5"        
      "Africa"        3 20.3 "Africa 20.3"      
      "Oceania"       4    6 "Oceania 6.0"      
      "North America" 5 16.3 "North America 16.3"
      "South America" 6   12 "South America 12.0"
      "Antarctica"    7  8.9 "Antarctica 8.9"    
      end
      label values name_and_value var2
      label def var2 1 "Europe 7.0", modify
      label def var2 2 "Asia 29.5", modify
      label def var2 3 "Africa 20.3", modify
      label def var2 4 "Oceania 6.0", modify
      label def var2 5 "North America 16.3", modify
      label def var2 6 "South America 12.0", modify
      label def var2 7 "Antarctica 8.9", modify
      For this, I would just lean to a horizontal bar chart.

      Code:
      graph hbar (asis) value, over(continent, sort(1) descending) bar(1, fcolor(none)) blabel(total, pos(base) size(medsmall)) yla(none) title(Continental areas (million km{sup:2}))
      Click image for larger version

Name:	continent_bars.png
Views:	1
Size:	10.3 KB
ID:	1324257





      The key points seem to be

      1. Ranking or sorting to show biggest to smallest is usually a good idea and bar charts support that directly.

      2. Bar charts (and also Cleveland dot charts) allow fine distinctions as well as coarse distinctions. You can see easily when one value is just smaller or just larger than another, which isn't true of pies or donuts. (Often you don't care, but if you don't nothing is lost.)

      3. Combining graph (what is the pattern?) and table (what is the value of?) roles is easy. (Those who have a phobia about "numbers on graphs" don't have to buy this.)

      4. Showing text labels legibly is essential. Here "North America" and "South America" are not especially long, but even so it's a challenge with many kinds of graph not to mess such labels up.

      5. Multicolour displays are good for small children and senior executives, but otherwise decorative at best and distracting at worst. (I don't know whether monochrome donuts are standard.)

      Comment


      • #4
        brilliant name. not my favorite either, but I've been explicitly requested to "bake" some (for senior executives indeed ) and I'm a lazy baker who doesnt wanna switch oven. i shall find an alternative software (spending time programming donuts...not worth it) or attempt educating them (again!)
        ps: catplot has made my life so much easier plenty of times so much thanks for it
        Last edited by natalia malancu; 29 Jan 2016, 06:15.

        Comment


        • #5
          You might look for the "polar" package. As I recall it will take some fiddling, and has its limits too.

          How about a donut chart of police stats?!
          Doug Hemken
          SSCC, Univ. of Wisc.-Madison

          Comment


          • #6
            i'll have a look at that, thanks.
            somehow I knew that joke was coming, so here's a new one: if it's a multi-level donut chart, should we actually call it a cronut chart?!

            Comment


            • #7
              unrelated: if I have a stacked graph without the over option (so just a categorical variable stacked as a column), whether I stacked frequencies or percentage, the size ratio between each block of the graph is similar, right?

              Comment


              • #8
                size ratio is exactly the same, one is just a rescaled version of the other
                Doug Hemken
                SSCC, Univ. of Wisc.-Madison

                Comment


                • #9
                  and by rescaled you mean the unit of reference is different (count as opposed to percentage).

                  Comment


                  • #10
                    Yes
                    Doug Hemken
                    SSCC, Univ. of Wisc.-Madison

                    Comment


                    • #11
                      As this thread is a few years old I thought I'd reup to see if anyone has seen any innovations.

                      While I generally concur with Nick in #2 ("best avoided") I have a specific application in mind where it would be nice for comparison purposes to be able to vary the area of the inner circle (or width of the "ring," I suppose) to represent frequency of some reference category.

                      Comment


                      • #12
                        What I said in #2 included also "They are just about programmable but would be hard work."

                        With a deep understanding of Stata class programming and the code underlying graph -- and to the best of my knowledge one person outside StataCorp has both, and it's not me -- it could probably be coded ab initio.

                        Otherwise with a good understanding of Stata ado programming and of how to use graph the route I would recommend would be to use graph twoway. Outer and inner circles would be done one half of a circle at a time using twoway function. And you switch off the axes! The detail here would bite, as e.g. you would have to work out where to put text all by yourself.

                        Comment


                        • #13
                          Maybe all is not lost, thanks to gr edit! I think I skipped some geometry classes back in the day, but are proportions consistent if you insert a circle inside a pie chart? Hopefully this helps John Mullahy. I highlight (in red) what controls the size of the inner circle, and the default size of the largest circle allowed by Stata within gr edit is 11.111, so below I specify 6 times this value in the code extracted from gr edit. Doing this allows a larger sized inner circle.

                          Code:
                          sysuse census, clear
                          gr pie, over(region) leg(off) scheme(s1color)
                          gr_edit .plotregion1.AddMarker added_markers editor .3084167963486522 .1804861369032551
                          gr_edit .plotregion1.added_markers_new = 1
                          gr_edit .plotregion1.added_markers_rec = 1
                          gr_edit .plotregion1.added_markers[1].style.editstyle  marker( symbol(circle) ///
                          linestyle( width( sztype(relative) val(.2) allow_pct(1)) color(white) pattern(solid) ///
                          align(inside)) fillcolor(white) size( sztype(relative) val(66.666) allow_pct(1)) angle(stdarrow) ///
                          symangle(zero) backsymbol(none) backline( width( sztype(relative) val(.2) allow_pct(1)) ///
                          color(black) pattern(solid) align(inside)) backcolor(black) backsize( sztype(relative) val(0) allow_pct(1)) ///
                          backangle(stdarrow) backsymangle(zero)) line( width( sztype(relative) val(.2) allow_pct(1)) color(black) ///
                          pattern(solid) align(inside)) area( linestyle( width( sztype(relative) val(.2) allow_pct(1)) color(ltbluishgray) ///
                          pattern(solid) align(inside)) shadestyle( color(ltbluishgray) intensity(inten100) fill(pattern10))) ///
                          label( textstyle( horizontal(center) vertical(middle) angle(default) size( sztype(relative) val(2.777) ///
                          allow_pct(1)) color(black) position() margin( gleft( sztype(relative) val(0) allow_pct(1)) gright( sztype(relative) ///
                          val(0) allow_pct(1)) gtop( sztype(relative) val(0) allow_pct(1)) gbottom( sztype(relative) val(0) allow_pct(1))) ///
                          linestyle( width( sztype(relative) val(.2) allow_pct(1)) color(black) pattern(solid) align(inside))) position(6) ///
                          textgap( sztype(relative) val(.6944) allow_pct(1)) format(`""') horizontal(default) vertical(default)) ///
                          dots( symbol(circle) linestyle( width( sztype(relative) val(.2) allow_pct(1)) color(black) pattern(solid) ///
                          align(inside)) fillcolor(black) size( sztype(relative) val(.1) allow_pct(1)) angle(horizontal) symangle(zero) ///
                          backsymbol(none) backline( width( sztype(relative) val(.2) allow_pct(1)) color(black) pattern(solid) align(inside)) ///
                          backcolor(black) backsize( sztype(relative) val(1.52778) allow_pct(1)) backangle(horizontal) backsymangle(zero)) ///
                          connect(direct) connect_missings(yes) editcopy
                          Res.:

                          Click image for larger version

Name:	Graph.png
Views:	1
Size:	29.8 KB
ID:	1553107

                          Comment


                          • #14
                            Thanks Nick and Andrew.

                            Andrew, your solution looks like it will work well for what I have in mind. I appreciate your sharing this code with me (and with Statalist).

                            Best wishes, John

                            Comment


                            • #15
                              #13 That gets a double prize for "Most impressive post likely today" and for "Gently underlining that Nick Cox can be wrong like anyone else".

                              Still, I wonder what the data are and whether these dessert graphics really are the best design. Can they be posted?

                              Comment

                              Working...
                              X