Skip to content

Commit

Permalink
v1.81
Browse files Browse the repository at this point in the history
  • Loading branch information
asjadnaqvi committed Apr 30, 2024
1 parent d77805a commit 1d75fab
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 27 deletions.
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ authors:
- family-names: "Naqvi"
given-names: "Asjad"
title: "Stata package ``streamplot''"
version: 1.7
date-released: 2024-04-25
version: 1.81
date-released: 2024-04-30
url: "https://github.com/asjadnaqvi/stata-streamplot"
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
![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.8
(25 Apr 2024)
# streamplot v1.81
(30 Apr 2024)

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 @@ -25,7 +25,7 @@ SSC (**v1.61**):
ssc install streamplot, replace
```

GitHub (**v1.8**):
GitHub (**v1.81**):

```
net install streamplot, from("https://raw.githubusercontent.com/asjadnaqvi/stata-streamplot/main/installation/") replace
Expand Down Expand Up @@ -60,7 +60,7 @@ The syntax for the latest version is as follows:
```stata
streamplot y x [if] [in], by(varname)
[ palette(str) smooth(num) labcond(str) offset(num) alpha(num) droplow yreverse cat(varname) recenter(top|mid|bot)
lcolor(str) lwidth(str) labsize(num) labcolor(color|palette) percent format(str) nolabel
lcolor(str) lwidth(str) labsize(num) labcolor(color|palette) percent format(str) nolabel area
tline tlcolor(str) tlwidth(str) tlpattern(str) yline(str)
xlabel(str) xtitle(str) ytitle(str) title(str) subtitle(str) note(str)
ysize(num) xsize(num) scheme(str) aspect(str) name(str) saving(str)
Expand Down Expand Up @@ -324,13 +324,29 @@ streamplot value_real year if countrycode=="TSA", by(category) smooth(2) palett
<img src="/figures/streamplot_labprop3.png" width="100%">


## v1.81 stacked area graph

```
streamplot value_real year if countrycode=="TSA", by(category) smooth(0) area recenter(bottom) ///
xsize(2) ysize(1) xtitle("") palette(tab Green-Orange-Teal) ///
xlabel(, angle(90)) labsize(2.2) offset(8) ///
title("{fontface Arial Bold:GDP Expenditures in South Asia (Constant 2015 USD billions)}") ///
note("World Bank Open Data.", size(2))
```

<img src="/figures/streamplot_labprop4.png" width="100%">


## Feedback

Please open an [issue](https://github.com/asjadnaqvi/stata-streamplot/issues) to report errors, feature enhancements, and/or other requests.


## Change log

**v1.81 (30 Apr 2024)**
- Added `area` option to allow stacked area graphs.

**v1.8 (25 Apr 2024)**
- Added `labprop` and `labscale()` options to allow easy label scaling.
- Added `share` and `percent` as substitutes.
Expand Down
Binary file added figures/streamplot_labprop4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions installation/stata.toc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
v 1.7
v 1.81
d STREAMPLOT: A package for creating stream plots in Stata
d
d Asjad Naqvi,
d [email protected]
d
d Distribution-Date: 20240401
d Distribution-Date: 20240430
d
d https://medium.com/the-stata-guide
d https://github.com/asjadnaqvi/Stata-schemes
Expand Down
34 changes: 23 additions & 11 deletions installation/streamplot.ado
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*! streamplot v1.8 (25 Apr 2024)
*! streamplot v1.81 (30 Apr 2024)
*! Asjad Naqvi ([email protected])

* v1.81 (30 Apr 2024): added area option to creat
* v1.8 (25 Apr 2024): added labscale option. Added percent/share as substitutes. more flexible for generic options.
* v1.7 (01 Apr 2024): trendline, yline, drop if by() is missing
* v1.61 (15 Jan 2024): fixed wrong locals. changed ylab to just lab.
Expand All @@ -27,7 +28,7 @@ version 15
[ NOLABel nodraw ] /// v1.5x
[ cat(varname) YREVerse ] /// // v1.6
[ tline TLColor(string) TLWidth(string) TLPattern(string) droplow ] /// // v1.7
[ * labprop labscale(real 0.3333) percent share ] // 1.8 options
[ * labprop labscale(real 0.3333) percent share area ] // 1.8 options


// check dependencies
Expand Down Expand Up @@ -82,8 +83,8 @@ preserve
collapse (sum) `yvar', by(`xvar' `by' `cat')


gen ones = 1
bysort `by': egen counts = sum(ones)
gen _ones = 1
bysort `by': egen counts = sum(_ones)
egen tag = tag(`by')
summ counts, meanonly

Expand All @@ -106,7 +107,7 @@ preserve
exit
}

drop ones tag counts
drop _ones tag counts

fillin `by' `xvar'
recode `yvar' (.=0)
Expand Down Expand Up @@ -175,6 +176,15 @@ preserve


replace `yvar' = 0 if `yvar' < 0 // this is technically wrong but we do it anyways // fix in later versions


if "`area'" != "" {
bysort `xvar': egen double _sum = sum(`yvar')
replace `yvar' = (`yvar' / _sum) * 100
drop _sum
}


tssmooth ma _ma = `yvar' , w(`smooth' 1 0)

// add the range variable on the x-axis
Expand All @@ -199,7 +209,6 @@ preserve
}



** preserve the labels for use later

local mylab: value label `by'
Expand Down Expand Up @@ -272,6 +281,12 @@ preserve
}


if "`area'" != "" { // overwrite
cap drop _meanval
gen _meanval = 0
}



foreach x of varlist _stack* {
gen double `x'_norm = `x' - _meanval
Expand All @@ -281,9 +296,6 @@ preserve

// this part is for the mid points

*summ `xvar'
*gen last = 1 if `xvar'==r(max)

gen double _ylab = .
gen double _yval = .
gen double _yshare = .
Expand Down Expand Up @@ -316,7 +328,7 @@ preserve
summ `xvar', meanonly
gen _xlab = r(max) if _yval!=.

**** automate this part
**** automate this part


ds _stack*norm
Expand All @@ -325,7 +337,7 @@ preserve


if "`format'" == "" {
if "`percent'"=="" & "`share'"=="" {
if "`percent'"=="" & "`share'"=="" & "`area'"=="" {
local format %15.0fc
}
else {
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.8
v 1.81
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: 20240426
d Distribution-Date: 20240430
d
d This version: 26 Apr 2024
d This version: 30 Apr 2024
d First version: 05 Dec 2021
d License: MIT
d
Expand Down
12 changes: 7 additions & 5 deletions installation/streamplot.sthlp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{smcl}
{* 26Apr2024}{...}
{* 30Apr2024}{...}
{hi:help streamplot}{...}
{right:{browse "https://github.com/asjadnaqvi/stata-streamplot":streamplot v1.8 (GitHub)}}
{right:{browse "https://github.com/asjadnaqvi/stata-streamplot":streamplot v1.81 (GitHub)}}

{hline}

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

{cmd:streamplot} {it:y x} {ifin}, {cmd:by}(varname)
{cmd:[} {cmd:palette}({it:str}) {cmd:smooth}({it:num}) {cmd:labcond}({it:str}) {cmd:offset}({it:num}) {cmd:alpha}({it:num}) {cmd:droplow} {cmdab:yrev:erse} {cmd:cat}({it:varname}) {cmdab:rec:enter}({it:top}|{it:mid}|{it:bot})
{cmdab:lc:olor}({it:str}) {cmdab:lw:idth}({it:str}) {cmdab:labs:ize}({it:num}) {cmdab:labc:olor}({it:color}|{it:palette}) {cmd:percent} {cmd:format}({it:str}) {cmdab:nolab:el}
{cmdab:lc:olor}({it:str}) {cmdab:lw:idth}({it:str}) {cmdab:labs:ize}({it:num}) {cmdab:labc:olor}({it:color}|{it:palette}) {cmd:percent} {cmd:format}({it:str}) {cmdab:area} {cmdab:nolab:el}
{cmd:tline} {cmdab:tlc:olor}({it:str}) {cmdab:tlw:idth}({it:str}) {cmdab:tlp:attern}({it:str}) {cmd:yline}({it:str}) {cmd:labprop} {cmd:labscale}({it:num}) {cmd:*}
{cmd:]}

Expand All @@ -43,6 +43,8 @@ For brevity, the following can be specified: {it:middle} = {it:mid} = {it:m}, {i

{p2coldent : {opt nolab:el}}Hide the variable labels.{p_end}

{p2coldent : {opt area}}Show stacked area graph. Options {opt recenter(bottom)} and {opt smooth(0)} are recommended with this option.{p_end}

{p2coldent : {opt droplow}}If there are fewer than 10 observations per {opt by()} variable, the command will throw an error. If only some groups have this issue,
then use the {opt droplow} option to drop these observations. This option is intended to quickly plot the data. Ideally, clean up the data before plotting.{p_end}

Expand Down Expand Up @@ -109,8 +111,8 @@ See {browse "https://github.com/asjadnaqvi/stata-streamplot":GitHub}.

{title:Package details}

Version : {bf:streamplot} v1.8
This release : 25 Apr 2024
Version : {bf:streamplot} v1.81
This release : 30 Apr 2024
First release: 06 Aug 2021
Repository : {browse "https://github.com/asjadnaqvi/stata-streamplot":GitHub}
Keywords : Stata, graph, stream plot
Expand Down

0 comments on commit 1d75fab

Please sign in to comment.