Announcement

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

  • Pie chart labeling

    Hello. I am trying to create a simple pie chart of sex distribution but the slice labels keep being on top of the title, as below.



    Click image for larger version

Name:	1.PNG
Views:	1
Size:	44.9 KB
ID:	1763212



    So, I moved the title to the bottom of the chart, but now it show the label anymore. What am I doing wrong? I have been googling, watching YouTube videos and reading manuals but I cannot seem to find the answer to this very simple problem. Can anyone help?



    Click image for larger version

Name:	2.PNG
Views:	1
Size:	43.6 KB
ID:	1763211
    Attached Files

  • #2
    You are using the scheme s2color. Note that recent versions of Stata have a different default scheme (stcolor). For your future posts, provide a reproducible example so that people do not spend time trying to reproduce your problem. Here, the label is outside the plot region. Either bring it to within the plot region using the -gap()- suboption of -plab()- or change the angle of the slice so that it is not in a position where the label extends outside the plot region. Here is a reproduction and an illustration of the latter solution.

    Code:
    sysuse census, clear
    graph pie pop, over(region) plab(1 percent, gap(33) color(red) size(medlarge)) ///
    pie(1, explode)  angle0(95) title(Percentage of population by census region, size(large))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	36.2 KB
ID:	1763222



    Code:
    sysuse census, clear
    graph pie pop, over(region) plab(1 percent, gap(33) color(blue) size(medlarge)) pie(1, explode)  ///
    angle0(80) title(Percentage of population by census region, size(large))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	37.5 KB
ID:	1763223

    Comment


    • #3
      Thank you! And apologies for the incomplete information. It works now. I made the angle at 45 so the slice appears to the side:

      graph pie, over(sex) pie(2, explode) angle0(45) plabel(2 percent, gap (22)) title(`"Proportion of Self-Harm incidents by gender, 2023"') legend(off)

      I am unable to paste the graph here or attach it for some reason, but it worked. Thanks!

      Comment


      • #4
        Ok, I managed. Here it is:

        Click image for larger version

Name:	Screenshot (264).png
Views:	1
Size:	90.5 KB
ID:	1763256

        Comment


        • #5
          I guess the point of the graph is to emphasize that one percentage is very small. (Is it really saying that only about 2% of self-harm incidence concerns females?)

          If so, a framed bar is one alternative. A longstanding objection to pie charts is that people are not so good at judging angles, but they are better at judging heights or lengths.

          We still don't have a data example, but a graphic can be produced using just the summary 2.157% -- and naturally more text is needed.

          Code:
          clear 
          set obs 1
          twoway scatteri 2.157 1 "2.157%", mlabpos(12) mlabsize(large) recast(bar) base(0) ///
          || scatteri 100 1, recast(bar) fcolor(none) ysc(off) xscale(off) legend(off)
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	19.0 KB
ID:	1763287

          Comment

          Working...
          X