Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
asjadnaqvi committed Nov 7, 2022
1 parent 0183f24 commit abc8cbd
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 51 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

![StataMin](https://img.shields.io/badge/stata-2015-blue) ![issues](https://img.shields.io/github/issues/asjadnaqvi/stata-arcplot) ![license](https://img.shields.io/github/license/asjadnaqvi/stata-arcplot) ![Stars](https://img.shields.io/github/stars/asjadnaqvi/stata-arcplot) ![version](https://img.shields.io/github/v/release/asjadnaqvi/stata-arcplot) ![release](https://img.shields.io/github/release-date/asjadnaqvi/stata-arcplot)

# arcplot v1.0
# arcplot v1.1

This package allows us to draw arc plots in Stata. It is based on the [Arc plot Guide](https://medium.com/the-stata-guide/stata-graphs-arc-plots-eb87015510e6) that I released in October 2021.
This package allows us to draw arc plots in Stata. It is based on the [Arc plot Guide](https://medium.com/the-stata-guide/stata-graphs-arc-plots-eb87015510e6) (October 2021).


## Installation
Expand All @@ -16,7 +16,7 @@ SSC (**v1.0**):
ssc install arcplot, replace
```

GitHub (**v1.0**):
GitHub (**v1.1**):

```
net install arcplot, from("https://raw.githubusercontent.com/asjadnaqvi/stata-arcplot/main/installation/") replace
Expand Down Expand Up @@ -56,7 +56,9 @@ The syntax for **v1.0** is as follows:
```
arcplot *num var* [if] [in], from}(str var) to(str var)
[ gap(num) arcpoints(num) palette(str) alpha(num) format(str)
lwidth(num) lcolor(str) vallabgap(str) vallabangle(str) vallabsize(num)
lwidth(num) lcolor(str)
labgap(str) labangle(str) labsize(str) labpos(str) labcolor(str)
vallabgap(str) vallabangle(str) vallabsize(str) vallabpos(str) vallabcolor(str)
xsize(num) ysize(num) title(str) subtitle(str) note(str) scheme(str) name(str) ]
```

Expand Down Expand Up @@ -104,6 +106,12 @@ Please open an [issue](https://github.com/asjadnaqvi/stata-arcplot/issues) to re
## Versions


**v1.1 (08 Nov 2022)**
- Several bug fixes.
- Better label controls.
- Gtools added for faster reshapes.


**v1.0 (21 Aug 2022)**
- Public release.

Expand Down
66 changes: 38 additions & 28 deletions installation/arcplot.ado
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
*! arcplot v1.0 22 Jun 2022. beta release
*! arcplot v1.1 (22 Jun 2022)
*! Asjad Naqvi

* v1.1 08Nov2022. Several bug fixes. Improvements to code. Gtools added.
* v1.0 22Jun2022. First beta release


**********************************
* Step-by-step guide on Medium *
**********************************

* if you want to go for even more customization, you can read this guide:
* Arc plots (Joy plots) (6 Oct, 2021)
* if you want to go for even more customization, you can read the
* Arc plots (6 Oct, 2021) guide:
* https://medium.com/the-stata-guide/stata-graphs-arc-plots-eb87015510e6


cap program drop arcplot


program arcplot, sortpreserve
program arcplot, // sortpreserve

version 15

syntax varlist(min=1 max=1 numeric) [if] [in], From(varname) To(varname) ///
[ gap(real 0.03) ARCPoints(real 50) palette(string) LColor(string) LWidth(string) alpha(real 50) ] ///
[ format(str) VALLABGap(str) VALLABSize(real 1.2) VALLABAngle(string) VALLAColor(string) LABColor(real 2) LABSize(real 2) ] ///
[ title(passthru) subtitle(passthru) note(passthru) scheme(passthru) name(passthru) xsize(passthru) ysize(passthru) ] ///
[ allopt graphopts(string asis) * ]
syntax varlist(min=1 max=1 numeric) [if] [in], From(varname) To(varname) ///
[ gap(real 0.03) ARCPoints(real 50) palette(string) LColor(string) LWidth(string) alpha(real 50) format(str) ] ///
[ VALLABGap(str) VALLABSize(string) VALLABAngle(string) VALLABColor(string) ] ///
[ LABGap(str) LABSize(string) LABAngle(string) LABColor(string) LABPos(string) ] ///
[ title(passthru) subtitle(passthru) note(passthru) scheme(passthru) name(passthru) xsize(passthru) ysize(passthru) ]


// check dependencies
capture findfile colorpalette.ado
if _rc != 0 {
display as error "The palettes package is missing. Install the {stata ssc install palettes, replace:palettes} and {stata ssc install colrspace, replace:colrspace} packages."
display as error "The {bf:palettes} package is missing. Click to install: {stata ssc install palettes, replace:palettes} and {stata ssc install colrspace, replace:colrspace}."
exit
}

capture findfile gtools.ado
if _rc != 0 {
display as error "The {bf:gtools} package is missing. Click to install: {stata ssc install gtools, replace:gtools}."
exit
}

capture findfile labmask.ado
if _rc != 0 {
display as error "The {it:labmask} package is missing. Click {stata ssc install labutil, replace} to install."
exit
qui install labutil, replace
}

marksample touse, strok

preserve

qui {

keep if `touse'
Expand All @@ -56,17 +62,17 @@ qui {

gen id = _n

reshape long lab, i(id) j(layer)
greshape long lab, i(id) j(layer)

encode lab, gen(lab2)

sort lab layer value
sort lab layer `varlist'
bysort lab: gen order = _n

egen tag = tag(lab)

expand 2 if tag==1, gen(tag2)
replace value = 0 if tag2==1 // duplicate entries are labeled as zero
replace `varlist' = 0 if tag2==1 // duplicate entries are labeled as zero
replace order = 0 if tag2==1
replace id = 0 if tag2==1

Expand All @@ -75,9 +81,9 @@ qui {

// generate cumulative values
sort lab layer order
bysort lab: gen double valsum = sum(value)
bysort lab: gen double valsum = sum(`varlist')

gen double valsumtot = sum(value)
gen double valsumtot = sum(`varlist')
sort lab layer order

// add gaps between arcs
Expand Down Expand Up @@ -142,7 +148,7 @@ qui {
// start future block. these are used much later in the last step after reshape
gen double from`x' = r(mean) // from node

summ value if id==`x' & layer==1, meanonly
summ `varlist' if id==`x' & layer==1, meanonly
gen double fval`x' = r(mean) // from value

summ order if id==`x' & layer==1, meanonly
Expand Down Expand Up @@ -223,20 +229,20 @@ qui {

sort lab layer order

keep _y1 _x1 _y2 _x2 ymid xmid arc* from* layer value lab2 fval* fmid*
keep _y1 _x1 _y2 _x2 ymid xmid arc* from* layer `varlist' lab2 fval* fmid*

gen id = _n // dummy for reshape


reshape long arcx_in arcy_in arcx_out arcy_out from fval fmid, i(id _x1 _y1 _x2 _y2 xmid ymid layer value lab2) j(num)
greshape long arcx_in arcy_in arcx_out arcy_out from fval fmid, i(id _x1 _y1 _x2 _y2 xmid ymid layer `varlist' lab2) j(num)

ren arcx_in arcx1
ren arcy_in arcy1

ren arcx_out arcx2
ren arcy_out arcy2

reshape long arcx arcy, i(id _x1 _y1 _x2 _y2 num lab2 layer value) j(level)
greshape long arcx arcy, i(id _x1 _y1 _x2 _y2 num lab2 layer `varlist') j(level)

// control variables
egen tag = tag(num)
Expand Down Expand Up @@ -271,10 +277,17 @@ qui {
if "`palette'" == "" local palette CET C1
if "`lcolor'" == "" local lcolor black
if "`lwidth'" == "" local lwidth none
if "`vallabangle'" == "" local vallabangle 90

if "`labcolor'" == "" local labcolor black
if "`labangle'" == "" local labangle 0
if "`labgap'" == "" local labgap 0.5
if "`labpos'" == "" local labpos 6
if "`labsize'" == "" local labsize 2

if "`vallabangle'" == "" local vallabangle 90
if "`vallabcolor'" == "" local vallabcolor black
if "`vallabgap'" == "" local vallabgap 2
if "`vallabsize'" == "" local vallabsize 1.2

if "`format'" == "" local format %9.0fc

Expand All @@ -292,8 +305,6 @@ qui {
local spikes `spikes' (pcspike _y1 _x1 _y2 _x2 if num==1 & lab==`x', lc( "`r(p`x')'") lwidth(1.5)) ||

}



local arcs

Expand All @@ -313,14 +324,13 @@ qui {
twoway ///
`arcs' ///
`spikes' ///
(scatter ymid xmid if num==1 & tag2==1, msize(vsmall) mcolor(none) mlabsize(`labsize') mlab(lab2) mlabpos(6) ) ///
(scatter _y fmid, mcolor(none) mlabsize(`vallabsize') mlab(fval2) mlabpos(12) mlabangle(`vallabangle') mlabgap(`vallabgap') ) ///
(scatter ymid xmid if num==1 & tag2==1, mcolor(none) mlabsize(`labsize') mlab(lab2) mlabpos(`labpos') mlabangle(`labangle') mlabgap(`labgap') ) ///
(scatter _y fmid , mcolor(none) mlabsize(`vallabsize') mlab(fval2) mlabpos(12) mlabangle(`vallabangle') mlabgap(`vallabgap') mlabcolor(`vallabcolor') ) ///
, legend(off) ///
ylabel(0 0.6, nogrid) xlabel(0 1, nogrid) aspect(0.6) ///
xscale(off) yscale(off) `scheme' `name' `title' `subtitle' `note' `xsize' `ysize'

}

restore

end
Expand Down
6 changes: 3 additions & 3 deletions installation/arcplot.pkg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
v 1.0
v 1.1
d {bf:ARCPLOT}: A Stata package for arc plots.
d See {bf:help arcplot} after installation.
d
Expand All @@ -9,9 +9,9 @@ d KW: graphs
d KW: arc plot
d
d
d Distribution-Date: 20220826
d Distribution-Date: 20221108
d
d This version: 26 Aug 2022
d This version: 08 Nov 2022
d First version: 21 Aug 2022
d License: MIT
d
Expand Down
43 changes: 28 additions & 15 deletions installation/arcplot.sthlp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{smcl}
{* 26August2022}{...}
{* 08November2022}{...}
{hi:help arcplot}{...}
{right:{browse "https://github.com/asjadnaqvi/stata-arcplot":arcplot v1.0 (GitHub)}}
{right:{browse "https://github.com/asjadnaqvi/stata-arcplot":arcplot v1.1 (GitHub)}}

{hline}

Expand All @@ -15,8 +15,10 @@ The command is based on the following guide on Medium: {browse "https://medium.c

{cmd:arcplot} {it:variable} {ifin}, {cmdab:f:rom}({it:str var}) {cmdab:t:o}({it:str var})
{cmd:[} {cmd:gap}({it:num}) {cmdab:arcp:oints}({it:num}) {cmd:palette}({it:str}) {cmd:alpha}({it:num}) {cmd:format}({it:str})
{cmdab:lw:idth}({it:num}) {cmdab:lc:olor}({it:str}) {cmdab:vallabg:ap}({it:str}) {cmdab:vallaba:ngle}({it:str}) {cmdab:vallabs:ize}({it:num}) {cmdab:vallabc:olor}({it:str})
{cmd:xsize}({it:num}) {cmd:ysize}({it:num}) {cmd:title}({it:str}) {cmd:subtitle}({it:str}) {cmd:note}({it:str}) {cmd:scheme}({it:str}) {cmd:name}({it:str}) {cmd:]}
{cmdab:lc:olor}({it:str}) {cmdab:lw:idth}({it:num})
{cmdab:labg:ap}({it:str}) {cmdab:laba:ngle}({it:str}) {cmdab:labs:ize}({it:num}) {cmdab:labc:olor}({it:str})
{cmdab:vallabg:ap}({it:str}) {cmdab:vallaba:ngle}({it:str}) {cmdab:vallabs:ize}({it:num}) {cmdab:vallabc:olor}({it:str})
{cmd:xsize}({it:num}) {cmd:ysize}({it:num}) {cmd:title}({it:str}) {cmd:subtitle}({it:str}) {cmd:note}({it:str}) {cmd:scheme}({it:str}) {cmd:name}({it:str}) {cmd:]}

{p 4 4 2}

Expand All @@ -43,17 +45,24 @@ The command is based on the following guide on Medium: {browse "https://medium.c

{p2coldent : {opt lw:idth(num)}}The outline width of the area fill. Default is {it:none}.{p_end}

{p2coldent : {opt vallabg:ap(str)}}The gap of the value labels from the horizontal bars. The default value is {it:2}.{p_end}

{p2coldent : {opt vallaba:ngle(str)}}The angle of the value labels. The default value is {it:90} for 90 degrees.{p_end}
{p2coldent : {opt labs:ize(str)}}The size of the category labels. The default value is {it:2}.{p_end}

{p2coldent : {opt labc:olor(str)}}The color of the category labels. The default value is {it:black}.{p_end}

{p2coldent : {opt laba:ngle(str)}}The angle of the category labels. The default value is {it:0} for horizontal.{p_end}

{p2coldent : {opt vallabs:ize(num)}}The size of the value labels. The default value is {it:1.2}.{p_end}
{p2coldent : {opt labg:ap(str)}}The gap of the category labels. The default value is {it:0.5}.{p_end}


{p2coldent : {opt vallabs:ize(str)}}The size of the value labels. The default value is {it:1.2}.{p_end}

{p2coldent : {opt vallabc:olor(str)}}The color of the value labels. The default value is {it:black}.{p_end}

{p2coldent : {opt labs:ize(num)}}The size of the category labels. The default value is {it:2}.{p_end}
{p2coldent : {opt vallaba:ngle(str)}}The angle of the value labels. The default value is {it:90} for 90 degrees.{p_end}

{p2coldent : {opt vallabg:ap(str)}}The gap of the value labels from the horizontal bars. The default value is {it:2}.{p_end}

{p2coldent : {opt labc:olor(num)}}The color of the category labels. The default value is {it:black}.{p_end}

{p2coldent : {opt title}, {opt subtitle}, {opt note}}These are standard twoway graph options.{p_end}

Expand All @@ -69,12 +78,16 @@ The command is based on the following guide on Medium: {browse "https://medium.c

{title:Dependencies}

The {browse "http://repec.sowi.unibe.ch/stata/palettes/index.html":palette} package (Jann 2018) is required for {cmd:arcplot}:
{cmd:arcplot} requires {browse "http://repec.sowi.unibe.ch/stata/palettes/index.html":palettes} package (Jann 2018):

{stata ssc install palettes, replace}
{stata ssc install colrspace, replace}

Even if you have these installed, it is highly recommended to update the dependencies:
and {browse "https://gtools.readthedocs.io/en/latest/":gtools} package:

{stata ssc install gtools, replace}

Even if you have these installed, it is highly recommended to check for their updates:
{stata ado update, update}

{title:Examples}
Expand All @@ -87,14 +100,14 @@ Check {browse "https://github.com/asjadnaqvi/arcplot":GitHub} for examples.

{title:Version history}


- {bf:1.1} : Various bug fixes. Improvements to label controls. Gtools added for faster reshaping.
- {bf:1.0} : First version.


{title:Package details}

Version : {bf:arcplot} v1.0
This release : 26 Aug 2022
Version : {bf:arcplot} v1.1
This release : 08 Nov 2022
First release: 21 Aug 2021
Repository : {browse "https://github.com/asjadnaqvi/arcplot":GitHub}
Keywords : Stata, graph, arc plot
Expand All @@ -117,4 +130,4 @@ Please submit bugs, errors, feature requests on {browse "https://github.com/asja

{p 4 8 2}Jann, B. (2018). {browse "https://www.stata-journal.com/article.html?article=gr0075":Color palettes for Stata graphics}. The Stata Journal 18(4): 765-785.


{p 4 8 2}Caceres, M. (2022). {browse "https://gtools.readthedocs.io/en/latest/":Gtools website}.
2 changes: 1 addition & 1 deletion installation/stata.toc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
v 1.0
v 1.1
d 'ARCPLOT': A Stata package for creating arc plots
d Asjad Naqvi,
d [email protected]
Expand Down

0 comments on commit abc8cbd

Please sign in to comment.