asjadnaqvi / stata-graphfunctions

A suite of programs to support Stata visualization customizations.
MIT License
7 stars 1 forks source link

shape donut #4

Open ericmelse opened 2 hours ago

ericmelse commented 2 hours ago

Dear Asjad,

I am not sure when a shape option becomes a (new) plot as such.

But, now you have added the shape option pie that can be set to be 'sliced', like your example using start(0) end(270), I am driven to ask also for a donut with the same shape options.

In my view a donut chart/plot is a more effective unary data visualition tool than a pie chart/plot (there is a ton of literature debating this, should you be interested in that I can provide materials). More pressing is that it is rather hard to draw a donut chart/plot using Stata. Andrew Musau provided a working solution for that, published as a Stata Tip in The Stata Journal. However, for that to work he still uses graph pie and next we have to work through a rather voluminous 'hack' using graph editor commands like:

sysuse census , clear
graph pie pop, over(region) scheme(sj) xsize(6) ysize(6) graphregion(fc(white) ilc(white) lc(white))
graph export "Example_Pie Chart1.png", width(1200) height(1200) as(png) replace // Change path as required

local csize=60
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( sztype(relative) val(.2) allow_pct(1)) color(white) pattern(solid) align(inside)) fillcolor(white) size( sztype(relative) val(`csize'*(93/100)) 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

which results in: donut1 So, mildly stated, I am happy that Andrew was able to provide a working solution as such for creating a donut chart/plot but I certainly am eager for a more flexible solution for this unary visualization ability using Stata.

Now, I suppose the first step would be to have a graphfunction available like shape donut not only with the parameters to set the starting and the ending position of donut slices but also for the donut radius (width). Once we have that available, I suggest to employ that in a (new) Stata package donut that you could enrich with those very fine options to control about anything you can think of. For example, byable sets of donuts plots over something, ordered in (#) rows or columns, legend controls, etc.

I do hope that the above is inspirational.

Best wishes, Eric

asjadnaqvi commented 2 hours ago

Dear Eric,

For a donut plot, you can already use sunburst. Maybe I should add an example there.

For graphfunctions I am still in the middle of putting it together, but I will add examples for how to generate donuts + other visualizations.

Also I am not a fan of this Stata basecode hacking that you posted above. This type of syntax from the base engine is not supposed to be used.

asjadnaqvi commented 2 hours ago

@ericmelse here is a basic syntax:

ssc install sunburst, replace

sysuse census , clear
sunburst pop, by(region) full format(%15.0fc)

donut1