Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sunburst donut plot/chart #12

Open
ericmelse opened this issue Oct 16, 2024 · 5 comments
Open

sunburst donut plot/chart #12

ericmelse opened this issue Oct 16, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@ericmelse
Copy link

Dear Asjad,
You provided code as an example how to create a donut plot/chart using sunburst
I have tried some options to adjust the plot using this code:
sunburst pop, by(region) full format(%15.0fc) labsize(3) wrap(7) plotreg(fc(gs12)) cfill(gs12) lc(gs12) lw(0 0)
which results in:
donut2
There are no errors as such, but I do observe some points for improvement while creating a donut:

  • Although I have set the color of the plot region, using the cfill and lc option to gs12, the cfill circle in the center (that is on top of 'pie slices' below it) does seems to keep its line set to white. Either separate options could be useful, like cfill(lc(gs12) fc(gs12)) or the option to set the line width to 0, like cfill(lw(0)). I prefer full control with all these options (whenever a line or an area is drawn).

  • It is very nice to have the option to wrap long strings of segment labels, like using wrap(7). But this option is rather limited when we can only 'hard code' it as the set number of characters, like 7 in the above example. A huge improvement would be the ability to wrap a string before or after a set character. E.g. for this case that would be wrap(b("(")), i.e. wrap b before the character open bracket "(". Which would put the data and their opening and closing brackets below the regions' text. Even smarter would then be to also drop the space character before the open bracket while centering the label in the donut segment.
    This would look like:
    donut2rotatedLabels
    Likewise we could have the option wrap(a(".")), i.e. wrap a after the character dot "." that is first encountered in the string of characters (no example of that here now).

  • More important would be an option to be able to rotate the start position of the donut sections that (I assume) follow also here the standard Stata procedure by starting from 0 degrees at the 3o' clock position (angles are counter-clockwise). I try to replicate the example published by Andrew Musau as a Stata Tip in The Stata Journal:
    donutAndrewMusau
    What really is the issue here is that Stata draws the segments clockwise starting from the 12o' clock position, whereas sunburst appears to start from the 5o' clock position, like:
    donut2rotatedLabels_numbered
    To get sunburst to replicate the same position of the regions we would need to rotate (counter-clockwise) about 201° which would look like:
    donut2rotatedLabelsRotated

I am not certain what would be more flexible, an option to control the rotation of the sunburst by any number of degrees [0,359] or something that rotates the start position of the first donut segment from the 5o' clock position to any other 'time' on the clock [1,12]. Probably both have their use. Or maybe I have it all wrong and something else requires a change in the sunburst code to have it draw categorical donuts clockwise from the 12o' clock position.

Best,
Eric

@asjadnaqvi asjadnaqvi added the enhancement New feature or request label Oct 16, 2024
@asjadnaqvi asjadnaqvi moved this from Unassigned to Next update in StataViz issue tracker Oct 16, 2024
@asjadnaqvi asjadnaqvi self-assigned this Oct 16, 2024
@asjadnaqvi
Copy link
Owner

asjadnaqvi commented Oct 16, 2024

Dear Eric,

Thanks for the detailed comments!

I have pushed v1.8 which now depends on graphfunctions package (install the latest one directly from GitHub for now) for label wrapping and generating the center circle fill. This considerably improves the fill options since we no longer rely on Stata functions to generate 2x half circles which create their own wierd artifacts with semi-visible lines.

Option rotate() has now been added but will only work if full for full circle is specified. For reordering the circles, I would suggest generating a numeric labeled variable to control for this.

On wrapping at a certain character: it is on my to do list.

donut2

@ericmelse
Copy link
Author

Many thanks Asjad, for your very fast follow up of my post.

Now I ran this code (after updating the ado's):
sunburst pop, by(region) full format(%15.0fc) labsize(3) wrap(7) plotreg(fc(gs12)) cfill(gs12) clc(gs12) clw(0) lc(gs12) lw(0) rotate(159)
which results in:
donut3
Somehow, some smart wrapping of the labels is already at work :).
And also I like the 'tilting' of the labels very much for better reading (although for NE that does not work yet).

I have a first question, i.e. an option request, could it be possible to set the radius of the center circle fill? I assume that it is set to a certain value in the sunburst ado file, but, it would useful to be able to increase or decrease the radius.

@asjadnaqvi
Copy link
Owner

asjadnaqvi commented Oct 16, 2024

Dear Eric, there is already a radius() option where you can specify a list. Since you have one layer, you can specify starting and ending radii as follows:

sunburst pop, by(region) format(%15.0fc) wrap(15) full rotate(90) radius(5 7)

donut2

@asjadnaqvi
Copy link
Owner

Also note that sunburst was designed for a different type of visualization but using it for a donut plot is a nice side effect :)

@asjadnaqvi asjadnaqvi moved this from Next update to Done in StataViz issue tracker Oct 16, 2024
@ericmelse
Copy link
Author

Dear Asjad,
Yes, thank you again. Indeed, that it is possible to use sunburst to create a donut plot is most welcome. Such a simple unary visualization might be perceived as 'not much' but many might have a use for it.
For one, the ability to use 'standard Stata code' facilitates concise coding and (more easy) replicability of results!
I intend to write a follow-up note about it for the TSJ as to document it also there.
If you do not mind me asking about options, I will further work on using sunburst for this purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

2 participants