Announcement

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

  • Pie chart inside donut chart

    Hi there,

    How is it possible to create a pie chart inside a donut chart like the attached one in Stata?
    Attached Files

  • #2
    It is I guess programmable, but not trivially.

    SJ-21-4 gr0089 . . . . . . . . Stata tip 143: Creating donut charts in Stata
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A. Musau
    Q4/21 SJ 21(4):1069--1073 (no commands)
    tip on creating donut charts

    I appreciate the two-level flavour of the data, but I would recommend a dot or bar chart every time over this awkward kind of graphic.
    Last edited by Nick Cox; 30 May 2023, 04:03.

    Comment


    • #3
      Hi Nick,

      Thanks for your reply.

      I like the graph style because it clearly shows that each is part of a total at 100 %.

      Comment


      • #4
        Indeed it does show that. Many people think that is the only advantage.

        Comment


        • #5
          I would recommend a dot or bar chart every time over this awkward kind of graphic.
          How would you make the same presentation with a bar graph? Feel free to quickly use some dummy numbers

          Comment


          • #6
            Fair enough.


            Code:
             
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input str4 which float(value axis)
            "A"  1 1
            "B" 32 2
            "C"  1 3
            "D" 11 4
            "E"  7 5
            "F"  1 6
            "G"  7 7
            "H" 41 8
            "I" 4 8
            end
            
            forval i = 1/8 { 
                label def axis `i' "`=which[`i']'", add 
            }
            
            label val axis axis 
            
            graph hbar (asis) value, over(which) over(axis) nofill asyvars stack legend(order(9) pos(5)) ysc(alt) blabel(total)
            Click image for larger version

Name:	notadonut.png
Views:	1
Size:	20.2 KB
ID:	1715521


            Comment


            • #7
              Thanks for your quick reply.

              My point is that this bar graph does not show that each bar is a part of a total of 100 %.

              Comment


              • #8
                No disagreement on that, if your readership needs to be told that or finds it reassuring then that will influence your choice of graph type.

                Comment


                • #9
                  To me the top question is how easily components are compared with each other, not with a total.

                  An issue that affects both graphs is whether the order of components is best as given. My guess is that there is substantive order in a sequence over what used to called primary, secondary and tertiary sectors of the economy

                  Comment


                  • #10
                    I have come this far now with the code below.

                    What is that best way to handle many long labels? Is it e.g. possible to use line breaks?

                    Is it possible to move the label a bit further from the slice and then draw lines from label to pie slice?

                    Code:
                    graph pie landbrug affald el_fjernvarme olie_gas_ve fremstillingserhverv serviceerhverv transport husholdninger, legend(off) plabel(_all name, gap(22) color(black)) plotregion(margin(15 15 15 15))
                    
                    graph save "gr1.gph", replace
                    
                    graph pie hvid ccs, pie(1, color(white)) legend(off) plabel(2 "CCS", gap(-40)) plotregion(margin(-135 45 45 45))
                    
                    graph save "gr2.gph", replace
                    
                    graph combine "gr1.gph" "gr2.gph"
                    Attached Files

                    Comment

                    Working...
                    X