Announcement

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

  • Pie chart with labels and percantage together on slice

    Hi,

    I am trying to make pie chart with label and percantage together on slices.(with legend off)

    The graph I am trying to have is similar to attached excel graph with big dataset.

    I have tried various search on google but cannot find the appropiate answer.

    Thanks for your help


    Regards
    Pankaj




    Attached Files

  • #2
    Don't even try that is my short answer, but I'll get there in due course.

    By the way, I can't read your Excel file. The assumption that everybody on this forum has MS Excel installed is quite wrong. It's best to post graphs as .png.

    A work-around for what I think you are asking is just to edit value labels to taste. That won't be congenial if you want to do this repeatedly.

    But I'd suggest strongly that bar charts are immensely preferable here. There are many ways of doing that

    Here is my code first for a reproducible example.

    Code:
    sysuse auto
    set scheme s1color 
    
    ssc inst pieplot 
    tab rep78
    label def rep78 1 "1 2.9%" 2 "2 11.6%" 3 "3 43.5%" 4 "4 26.1%" 5 "5 15.9%"
    label val rep78 rep78
    pieplot rep78
    
    ssc inst catplot 
    label val rep78
    catplot rep78, percent blabel(bar , format(%2.1f)) ysc(r(. 46))
    I didn't use graph pie, but used instead pieplot (SSC). That's just a wrapper for graph pie. I use graph pie so rarely that I can't remember its syntax, so I wrote a wrapper with a different syntax.



    There are many problems with pie charts. Even for this example with just 5 categories, it's hard to avoid a mess. The label for the smallest category inevitably overflows the area of the pie slice. For say 10 or more categories, the problems will usually be compounded. More fundamentally, we are not very good at decoding angles on graphs. Yet more, extending pie charts to even two-way breakdowns does not work well.

    The main advantage of a pie chart is perhaps its familiarity. If you are preparing a presentation to junior school-children or senior executives, a pie chart could be a competitor. Otherwise researchers deserve better.

    The colour choice here is just the default and could be improved.

    A bar chart does not have these disadvantages. Here I used catplot (SSC), which in this example is a wrapper for graph hbar.



    That design will do well for even 20-30 categories. There is much scope for tinkering with details. Here is one more example.



    The code for that is
    Code:
     
    catplot rep78, percent blabel(bar , pos(base) format(%2.1f)) bar(1, bfcolor(none)) ysc(off)
    Attached Files

    Comment


    • #3
      Hi Nick

      Thanks for your reply.
      Yes I was using pie chart as it is a long tradition to show activities in pie chart. And as a drawback my auditions are not researchers

      Would it be possible for catplot/?? to plot sum/mean of the variables ?

      Thanks
      Regards
      Pankaj gaur


      Comment


      • #4
        The purpose of catplot is explained in its help as drawing plots of frequencies, fractions or percents of categorical data. For plotting sums, means, etc. use graph hbar, graph bar or graph dot directly.

        Talking of traditions: the tradition of using bar charts is arguably much older than that of using pie charts, but how much depends on what you include as a bar chart. And it's now a century since Willard Cope Brinton. 1914. Graphic methods for presenting facts. New York: Engineering Magazine Company argued that

        "The circle with sectors is not a desirable form of presentation" (p.6)

        (The terminology of "pie charts" was introduced by others at about the same time.)

        I'd guess that your audience is capable of understanding bar charts, whatever other limitations they may have. But the choice is first yours, unless you are under orders. Which works better for your data?

        Comment


        • #5
          Hi, Pankaj.

          "Traditions" often serve to retard progress. For audiences in general, not only researchers, research in graphics has shown that people perceive angles and areas less accurately than lengths. Some researchers go so far as to say that pie charts should not be used at all.

          Nick's bar charts are much more effective than the pie chart. I would improve them in two ways: replace each bar with a line, ending at a suitable plotting symbol (such as a small filled circle); and move the numbers out of the plot window (if you need to present the numbers, use a table; don't clutter the display with them).

          You could consider trying to move your audience out of the past and into the present by presenting the pie chart and then a "dot chart" of the type I mentioned in the preceding paragraph (perhaps with the categories in order of their percentages). Depending on the data that you are presenting, it may be clear to everyone that the dot chart is a better display.

          For a helpful discussion, with examples, I suggest the book Creating More Effective Graphs by Naomi Robbins (Wiley 2005, but now with a different publisher. See her website: www.nbr-graphs.com).

          David Hoaglin

          Comment


          • #6
            Naturally, I agree with David Hoaglin in spirit. I am very positive about the kinds of chart he mentions, and have discussed them in various places, but have found much market puzzlement and resistance to them, which is why I often compromise at bar charts.

            I don't necessarily agree about the numbers in or on the bar charts. I am very fond of display that hybridize graphs and tables. Elsewhere I have moved the numbers to the margins, so I don't feel dogmatic on this point.

            Comment


            • #7
              graph pie if Positive_antibiotic != 3, over(Positive_antibiotic) intensity(40) ///
              plabel(2 "Negative" "`maleN' (43.9%)") ///
              plabel(1 "Positive" "`femaleN' (`fpercent'%)") ///
              title("Antibiotic use prevalence", span size(medium)) ///
              graphregion(color(white)) ///
              bgcolor(white)
              Hi what if I want the plabel positive to be blue in colour and negative to be green.Kindly help using the above code

              Comment


              • #8
                I mean the sclice for positive to be blue and negative to be green

                Comment

                Working...
                X