Skip to content

Commit

Permalink
v1.51
Browse files Browse the repository at this point in the history
  • Loading branch information
asjadnaqvi committed May 28, 2023
1 parent 809f734 commit 150c982
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 36 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![StataMin](https://img.shields.io/badge/stata-2015-blue) ![issues](https://img.shields.io/github/issues/asjadnaqvi/stata-streamplot) ![license](https://img.shields.io/github/license/asjadnaqvi/stata-streamplot) ![Stars](https://img.shields.io/github/stars/asjadnaqvi/stata-streamplot) ![version](https://img.shields.io/github/v/release/asjadnaqvi/stata-streamplot) ![release](https://img.shields.io/github/release-date/asjadnaqvi/stata-streamplot)

# streamplot v1.5
# streamplot v1.51

This package provides the ability to generate stream plots in Stata. It is based on the [Streamplot Guide](https://medium.com/the-stata-guide/covid-19-visualizations-with-stata-part-10-stream-graphs-9d55db12318a) (December 2020).

Expand All @@ -14,7 +14,7 @@ SSC (**v1.5**):
ssc install streamplot, replace
```

GitHub (**v1.5**):
GitHub (**v1.51**):

```
net install streamplot, from("https://raw.githubusercontent.com/asjadnaqvi/stata-streamplot/main/installation/") replace
Expand Down Expand Up @@ -50,7 +50,7 @@ graph set window fontface "Arial Narrow"

## Syntax

The syntax for **v1.5** is as follows:
The syntax for **v1.51** is as follows:

```
streamplot y x [if] [in], by(varname) [ palette(str) smooth(num) alpha(num) labcond(str) offset(num) droplow precent format
Expand Down Expand Up @@ -186,6 +186,11 @@ Please open an [issue](https://github.com/asjadnaqvi/stata-streamplot/issues) to

## Versions

**v1.51 (20 Nov 2022)**
- Cleaned up `labcond()` to align it with other packages.
- `offset()` changed to percentages to align it with other packages.
- Minor code cleanups, updates to defaults, and help file.

**v1.5 (20 Nov 2022)**
- Option to recenter the graphs added.
- Improve the precision of the calculations.
Expand Down
6 changes: 4 additions & 2 deletions installation/stata.toc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
v 1.5
d STREAMPLOT: A package for creating streamplots in Stata
v 1.51
d STREAMPLOT: A package for creating stream plots in Stata
d
d Asjad Naqvi,
d [email protected]
d
d Distribution-Date: 20230528
d
d https://medium.com/the-stata-guide
d https://github.com/asjadnaqvi/Stata-schemes

43 changes: 23 additions & 20 deletions installation/streamplot.ado
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
*! streamplot v1.5 (20 Nov 2022)
*! streamplot v1.51 (28 May 2023)
*! Asjad Naqvi ([email protected])

* v1.5 (20 Nov 2022): recenter option added. improved variable precision.
* v1.4 (08 Nov 2022): Major code cleanup and some parts reworked. Observation checks. Palette options. label controls.
* v1.3 (20 Jun 2022). Add marker labels and format options
* v1.2 14 Jun 2022: passthru optimizations. error checks. reduce the default smoothing. labels fix
* v1.1 08 Apr 2022
* v1.0 06 Aug 2021
* v1.51 (28 May 2023): Clean up labcond and offset changes to percentages.
* v1.5 (20 Nov 2022): recenter option added. improved variable precision.
* v1.4 (08 Nov 2022): Major code cleanup and some parts reworked. Observation checks. Palette options. label controls.
* v1.3 (20 Jun 2022): Add marker labels and format options
* v1.2 (14 Jun 2022): passthru optimizations. error checks. reduce the default smoothing. labels fix
* v1.1 (08 Apr 2022)
* v1.0 (06 Aug 2021)

**********************************
* Step-by-step guide on Medium *
Expand All @@ -25,9 +26,9 @@ program streamplot, sortpreserve

version 15

syntax varlist(min=2 max=2 numeric) [if] [in], by(varname) [palette(string) alpha(real 100) smooth(real 3)] ///
[ LColor(string) LWidth(string) labcond(string) ] ///
[ YLABSize(string) YLABel(varname) YLABColor(string) offset(real 0.12) droplow ] ///
syntax varlist(min=2 max=2 numeric) [if] [in], by(varname) [palette(string) alpha(real 100) smooth(real 3) ] ///
[ LColor(string) LWidth(string) labcond(real 0) ] ///
[ YLABSize(string) YLABel(varname) YLABColor(string) offset(real 15) droplow ] ///
[ xlabel(passthru) xtitle(passthru) title(passthru) subtitle(passthru) note(passthru) scheme(passthru) name(passthru) xsize(passthru) ysize(passthru) ] ///
[ PERCENT FORMAT(string) RECenter(string) ]

Expand All @@ -43,15 +44,14 @@ version 15
capture findfile labmask.ado
if _rc != 0 {
qui ssc install labutil, replace
exit
}

marksample touse, strok
gettoken yvar xvar : varlist


* Definition of locals - Default format
if `"`format'"' == "" local format "%12.0f"
if `"`format'"' == "" local format "%12.0fc"



Expand All @@ -60,6 +60,8 @@ preserve

keep if `touse'

isid `varlist' `by' // duplicates check

gen ones = 1
bysort `by': egen counts = sum(ones)
egen tag = tag(`by')
Expand Down Expand Up @@ -145,7 +147,7 @@ preserve
summ `xvar' if ``yvar'_ma7' != ., meanonly

local xrmin = r(min)
local xrmax = r(max) + ((r(max) - r(min)) * `offset')
local xrmax = r(max) + ((r(max) - r(min)) * (`offset' / 100))

*cap drop stack_`yvar'

Expand Down Expand Up @@ -260,23 +262,24 @@ drop lastsum*

foreach x of numlist 1/`items' {

if "`labcond'" != "" {
local condition "& `yvar'`x' `labcond'"
}
else {
local condition
}

* Addition of percent and format (Marc Kaulisch)
if `"`percent'"'!="" {
local ylabvalues `"string(`yvar'`x'_share, `"`format'"') + "%""'

local labvar `yvar'`x'_share

}
else {
local ylabvalues `"string(`yvar'`x', `"`format'"')"'

local labvar `yvar'`x'
}

di "`labvar'"

local t : var lab `yvar'`x'
gen label`x'_`yvar' = "`t'" + " (" + `ylabvalues' + ")" if last==1 `condition' //
gen label`x'_`yvar' = "`t'" + " (" + `ylabvalues' + ")" if last==1 & `labvar' >= `labcond'

}

Expand Down
6 changes: 3 additions & 3 deletions installation/streamplot.pkg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
v 1.5
v 1.51
d {bf:STREAMPLOT}: A package for creating streamplots in Stata
d
d Requires: Stata version 15 or higher.
Expand All @@ -7,9 +7,9 @@ d KW: Stata
d KW: graphs
d KW: streamplot
d
d Distribution-Date: 20221120
d Distribution-Date: 20230528
d
d This version: 20 Nov 2022
d This version: 28 May 2023
d First version: 05 Dec 2021
d License: MIT
d
Expand Down
23 changes: 15 additions & 8 deletions installation/streamplot.sthlp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{smcl}
{* 20Nov2022}{...}
{* 23May2023}{...}
{hi:help streamplot}{...}
{right:{browse "https://github.com/asjadnaqvi/stata-streamplot":streamplot v1.5 (GitHub)}}
{right:{browse "https://github.com/asjadnaqvi/stata-streamplot":streamplot v1.51 (GitHub)}}

{hline}

Expand Down Expand Up @@ -45,7 +45,7 @@ Default is {stata colorpalette tableau:{it:tableau}}.{p_end}
{p2coldent : {opt rec:enter(options)}}This option changes where the graph is recentered. The default option is {opt rec:enter(middle)}. Additional options are {opt rec:enter(top)} or {opt rec:enter(bottom)}.
For brevity, the following can be specified: {it:middle} = {it:mid} = {it:m}, {it:top} = {it:t}, {it:bottom} = {it:bot} = {it:b}.{p_end}

{p2coldent : {opt offset(num)}}Extends the x-axis range to accommodate labels. The default value is {it:0.12} or 12% of {it:xmax-xmin}.{p_end}
{p2coldent : {opt offset(num)}}Extends the x-axis range to accommodate labels. The default value is {opt offset(15)} for 15% of {it:xmax-xmin}.{p_end}

{p2coldent : {opt ylabc:olor(str)}}Either takes on a named Stata color, e.g. {it:ylabc(red)} for red labels.
If {it:ylabc(palette)} is specified, labels are colored based on the color palette.{p_end}
Expand All @@ -58,9 +58,8 @@ If {it:ylabc(palette)} is specified, labels are colored based on the color palet

{p2coldent : {opt xlabel()}}This is the standard twoway graph option for labeling and formatting the x-axis. {p_end}

{p2coldent : {opt labcond(str)}}Labels have the group name and the value of the last observation in brackets. The label condition can be used to limit the number of labels shown.
For example if we want to label only values which are greater than a certain threhold, then we can write {it:labcond(>= 10000)}. Currently only one condition is supported.
Here the main aim is to clean up the figure especially if labels are bunched on top of each other. See example below.{p_end}
{p2coldent : {opt labcond(num)}}The label condition can be used to limit the number of labels shown.
For example, {opt labcond(100)} will only shows labels where the last value is greater than 100.{p_end}

{p2coldent : {opt lw:idth(str)}}The line width of the area stroke. The default is {it:0.05}.{p_end}

Expand Down Expand Up @@ -98,8 +97,8 @@ Marc Kaulisch has suggested several useful features across various versions.

{title:Package details}

Version : {bf:streamplot} v1.6
This release : 20 Nov 2022
Version : {bf:streamplot} v1.61
This release : 23 May 2023
First release: 06 Aug 2021
Repository : {browse "https://github.com/asjadnaqvi/stata-streamplot":GitHub}
Keywords : Stata, graph, stream plot
Expand All @@ -114,4 +113,12 @@ Twitter : {browse "https://twitter.com/AsjadNaqvi":@AsjadNaqvi}

{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}Jann, B. (2022). {browse "https://ideas.repec.org/p/bss/wpaper/43.html":Color palettes for Stata graphics: An update}. University of Bern Social Sciences Working Papers No. 43.


{title:Other visualization packages}

{psee}
{helpb arcplot}, {helpb alluvial}, {helpb bimap}, {helpb bumparea}, {helpb bumpline}, {helpb circlebar}, {helpb circlepack}, {helpb clipgeo}, {helpb delaunay}, {helpb joyplot},
{helpb marimekko}, {helpb sankey}, {helpb schemepack}, {helpb spider}, {helpb streamplot}, {helpb sunburst}, {helpb treecluster}, {helpb treemap}

0 comments on commit 150c982

Please sign in to comment.