Announcement

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

  • Double pie chart without double title

    Hello,
    I am trying to make two pie charts to represent two binary variables. For example, gender and smoker/non smoker.

    Right now my command is:
    graph pie, over(smokingstatus) by (gender)
    title("Percent of men vs. women who smoke)

    However, that title comes up twice, once on top of each of the pie charts. Is there a way to make it one title across both charts?

    Thank you! Newbie here!

  • #2
    Welcome!!

    There is a program from the ssc called grc1leg2 written by Mead Over and updated by Vince Wiggins (StataCorp) that combines legends and or titles across panel graphs. Type
    findit grc1leg2 in Stata to check it out if you have Stata14+. That said, there might very well be a native solution without having to install additional packages. We can see what the other experts on this list have to say.

    ​​​​​​​Meanwhile, if you post some of your data using -dataex-, you might very well see someone post a solution using your data directly, saving you all the trouble. Folks here also are particular about real names. Sorry if the profile name is actually your real name.

    Comment


    • #3
      The trick is that when using -by( )-, a whole bunch of options need to instead be placed within the "by( )" option, rather than as their own option. So what you'd want to do is:
      Code:
      graph pie, over(smokingstatus) by(gender, title("Percent of men vs. women who smoke") note(" "))
      Note that I also included the -note(" ")- option within the -by( ) option to remove the silly "Graphs by smokingstatus" note that appears at the bottom by default.

      Hope this helps!

      Comment


      • #4
        note("") is even better.

        In the UK in 2022 14.6% of men smoked compared with 11.2% of women

        https://www.ons.gov.uk/peoplepopulat...atbritain/2022

        and in all such cases there are just two data points, which could be put in a single dot chart. In fact, you could easily put more information in the display, such as a breakdown by age, or data on vaping.



        Last edited by Nick Cox; 14 Jan 2024, 02:48.

        Comment


        • #5
          It's elementary but also fundamental that percent who don't is 100 minus percent who do. One percent suffices.

          We're almost 40 years on from Cleveland's American Statistician paper https://www.jstor.org/stable/2683401 pushing dot charts -- yet researchers are strangely reluctant to use such a simple idea.

          Indeed, similar plots were used in early editions of Snedecor's classic text.

          Snedecor, G.W. 1937. Statistical Methods Applied to Experiments in Agriculture and Biology. Ames, IA: Collegiate Press. See Figures 2.1, 2.3 (pp.24, 39). See
          also 1938 edition from Iowa State College Press (pp.27, 42). See also 1940 edition from Iowa State College Press (pp.27, 42). See also 1946 edition from Iowa
          State College Press (pp.33, 51). See also 1956 edition from Iowa State University Press (p.39).

          Oddly, or otherwise, these were dropped when W.G. Cochran took over in later editions. Were they considered too obvious?

          Whatever the history, consider this dataset in loosely similar territory on alcohol drinking. https://news.gallup.com/poll/467507/...k-alcohol.aspx

          For graphical purposes, small effort to make the results a dataset like this pays off later:

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float var1 str20 var2 float var3 str35 var4 float var5
          1 "Household income"      1 "$100,000 or more"                   80
          1 "Household income"      2 "$40,000 to $99,999"                 63
          1 "Household income"      3 "Less than $40,000"                  49
          2 "Education"             4 "Postgraduate"                       75
          2 "Education"             5 "College graduate only"              76
          2 "Education"             6 "Some college"                       65
          2 "Education"             7 "No college"                         51
          3 "Religious attendance"  8 "Seldom/never"                       69
          3 "Religious attendance"  9 "Nearly weekly/Monthly"              63
          3 "Religious attendance" 10 "Weekly"                             50
          4 "Religious preference" 11 "None/Atheist/Agnostic"              67
          4 "Religious preference" 12 "Protestant/Christian (nonspecific)" 60
          4 "Religious preference" 13 "Catholic"                           68
          5 "Gender"               14 "Men"                                66
          5 "Gender"               15 "Women"                              60
          6 "Age"                  16 "18-20"                              60
          6 "Age"                  17 "21-29"                              71
          6 "Age"                  18 "30-49"                              70
          6 "Age"                  19 "50-64"                              64
          6 "Age"                  20 "65+"                                54
          7 "Ethnicity"            21 "Non-Hispanic white adults"          68
          7 "Ethnicity"            22 "Hispanic adults"                    59
          7 "Ethnicity"            23 "Black adults"                       50
          end
          Here is one I fired up moderately quickly.

          Code:
          graph dot (asis) var5, over(var4, sort(var3) label(labsize(small))) over(var2) nofill exclude0 yla(50(10)80) ysc(r(45 .) alt) title(% US adults drinking alcohol) blabel(bar) linetype(line) lines(lc(gs12) lw(vthin))
          Some people would want different colours, and so forth, which is just a different question.

          Who would really prefer 23 pie charts in a composite?

          Click image for larger version

Name:	alcohol.png
Views:	1
Size:	72.4 KB
ID:	1739753


          Small details:

          * If you don't want the numeric labels, leave them out.

          * If you think the text takes up too much space, consider abbreviations at your own risk.

          * With a dot chart, you don't have to show zero on the magnitude axis if you don't want to,

          * I find that graphs with the default of dotted grid lines often don't travel well on export to other software. Very thin light grey lines work better.





          Comment


          • #6
            Another take is to suppress the outermost text labels, such as "Age", "Gender", and so forth with over(var2, label(nolabels)). The labels for Religious attendance might then need a tweak of some kind.

            Comment

            Working...
            X