Announcement

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

  • #16
    Thanks Nick. I think you can get all the functionality of a donut chart including inserting the category names within the graph, choosing colors and specifying opacity. I am not motivated to do all this, but here is the bare minimum.

    Code:
    sysuse census, clear
    gr pie, over(region) scheme(s1color) legend(position(2) col(1)) plabel(_all percent, gap(10))
    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
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	38.0 KB
ID:	1553153

    Last edited by Andrew Musau; 14 May 2020, 10:19.

    Comment


    • #17
      Khin-Maung tested the code in #13 using Stata 15 and discovered that some options in the code are not allowed. I was able to replicate this in my copy of Stata 15. Here is his email:

      Dear Andrew,
      I tried to use your Stata code posted at the Statalist on 20 May 2020 to write the Stata code for donut chart progress analysis using same dataset: census data.
      I use the same code as you posted without making any changes.
      I got a pie chart, but not a donut chart as you posted.
      I use the code as you posted without making any changes.
      The error message reported that ‘option(s) sztype(relative) not allowed
      I use Stata v15.
      I would appreciate it if I you could provide a suggestion.

      Thanks in advance,

      Best,
      Khin M Nyunt
      Research Fellow
      Myanmar Development Institute, Myanmar

      The following works in Stata 15.1, and is extracted from the graph editor code as was done in #13. Below, the local "csize" defines the area of the inner circle as a percentage of the pie chart's area.

      Code:
      sysuse census, clear
      gr pie, over(region) scheme(s1color) legend(off) ///
      plabel(_all name, gap(24) size(medlarge)) 
      
      local csize=70
      gr_edit .plotregion1.AddMarker added_markers editor .0715713654788885 -.0361049561829105
      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(thin) color(white) pattern(solid) align(inside)) fillcolor(white) ///
      size(`=`csize'*(93/100)') angle(stdarrow) symangle(zero) backsymbol(none) backline( width(thin) ///
      color(black) pattern(solid) align(inside)) backcolor(black) backsize(zero) ///
      backangle(stdarrow) backsymangle(zero)) line( width(thin) color(black) pattern(solid) ///
      align(inside)) area( linestyle( width(thin) color(gs15) pattern(solid) align(inside)) ///
      shadestyle( color(gs15) intensity(inten100) fill(pattern10))) label( textstyle( ///
      horizontal(center) vertical(middle) angle(default) size(small) color(black) position() ///
      margin(zero) linestyle( width(thin) color(black) pattern(solid) align(inside))) ///
      position(6) textgap(half_tiny) horizontal(default) vertical(default)) dots( symbol(circle) /// 
      linestyle( width(thin) color(black) pattern(solid) align(inside)) fillcolor(black) ///
      size(vtiny) angle(horizontal) symangle(zero) backsymbol(none) backline( width(thin) ///
      color(black) pattern(solid) align(iside)) backcolor(black) backsize(medium) ///
      backangle(horizontal) backsymangle(zero)) connect(direct) connect_missings(yes) editcopy

      Comment


      • #18
        Firstly, great work. Secondly, how does one get access to how gr_edit works? There doesnt seem to be any section of the manual on it. Is there some way you are able to see these codes? Will be great if you can help out

        Comment


        • #19
          gr_edit is undocumented. Search the forum and you will find several discussions about this. As far as I can see, it works like a regular command, executing lines of code retrieved from the graph recording.

          Comment


          • #20
            Clever is always good, but I just want to stick by the points in #3 -- which no-one rebutted.

            Comment


            • #21
              Dear Mr Andrew Musau and ALL,

              Could someone guide me how to draw like this double, triple donut chart?

              Thanks for my request.
              Best wishes,
              Win
              Click image for larger version

Name:	COPD-136256-F02.jpg
Views:	1
Size:	124.6 KB
ID:	1598223

              Comment


              • #22
                The graph edit hack won't work for this design. You may be able to program it using twoway function, but I don't think that it is worth the effort. I would just switch to some other specialized software that has this kind of chart programmed.

                Comment


                • #23
                  Anyone who has skimmed this thread won't be surprised at a suggestion from me to do something else.

                  These data are evidently percents in a 3 x 3 table, and the use of annuli in circular coordinates is just gratuitous. Hence why not a two-way bar chart?

                  Detail: I won't willingly show red and green on the same graph.

                  Detail: The order of columns is just alphabetical, but seems to work as well as any other. It could easily be tweaked.


                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input str20 which str8 medications float percent
                  "Dosage form"          "All"      45.8
                  "Dosage frequency"     "All"      41.7
                  "Additional direction" "All"      12.5
                  "Dosage form"          "COPD"     22.2
                  "Dosage frequency"     "COPD"     66.7
                  "Additional direction" "COPD"     11.1
                  "Dosage form"          "Non-COPD" 62.1
                  "Dosage frequency"     "Non-COPD" 24.1
                  "Additional direction" "Non-COPD" 13.8
                  end
                  
                  set scheme s1color
                  
                  * mycolours is from SSC
                  mycolours
                  
                  * tabplot is from Stata Journal
                  tabplot which medications [iw=percent] , showval ytitle("") xtitle("") ///
                  subtitle(% by medications) xsc(alt) yreverse separate(which)           ///
                  bar1(color("`sky'")) bar2(color("`ora'")) bar3(color("`bgr'"))
                  Click image for larger version

Name:	notadonut.png
Views:	1
Size:	29.3 KB
ID:	1598241

                  Last edited by Nick Cox; 17 Mar 2021, 03:31.

                  Comment


                  • #24
                    Curmudgeonly comment: they should be called "don't do it charts".

                    But, but, but: show me your best examples and I might change my mind. (I am already shifting on subtle colours as being helpful as well as decorative.)

                    Comment

                    Working...
                    X