Skip to content

asjadnaqvi/stata-ternary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StataMin issues license Stars version release

Installation | Syntax | Examples | Feedback | Change log


ternary_banner


ternary v1.1

(12 Sep 2024)

This package provides the ability to draw tri-variate plots in Stata.

Installation

The package can be installed via SSC or GitHub. The GitHub version, might be more recent due to bug fixes, feature updates etc, and may contain syntax improvements and changes in default values. See version numbers below. Eventually the GitHub version is published on SSC.

The SSC version (v1.0):

ssc install ternary, replace

Or it can be installed from GitHub (v1.1):

net install ternary, from("https://raw.githubusercontent.com/asjadnaqvi/stata-ternary/main/installation/") replace

The palettes package is required to run this command:

ssc install palettes, replace
ssc install colrspace, replace

Even if you have the package installed, make sure that it is updated ado update, update.

If you want to make a clean figure, then it is advisable to load a clean scheme. These are several available and I personally use the following:

ssc install schemepack, replace
set scheme white_tableau  

You can also push the scheme directly into the graph using the scheme(schemename) option. See the help file for details or the example below.

I also prefer narrow fonts in figures with long labels. You can change this as follows:

graph set window fontface "Arial Narrow"

Syntax

The syntax for the latest version is as follows:

        ternary varL varR varB [if] [in], [ cuts(num) zoom fill points lines labels colorL(str) colorR(str) colorB(str) lwidth(str) msymbol(str) msize(str) mcolor(str) mlcolor(str) mlwidth(str) labcolor(str) ticksize(str) *  ]

See the help file help ternary for details.

The most basic use is as follows:

ternary varL varR varB

representing left, right and bottom variables respectively.

Citation guidelines

Software packages take countless hours of programming, testing, and bug fixing. If you use this package, then a citation would be highly appreciated. Suggested citations:

in BibTeX

@software{ternary,
   author = {Naqvi, Asjad},
   title = {Stata package ``ternary''},
   url = {https://github.com/asjadnaqvi/stata-ternary},
   version = {1.0},
   date = {2024-08-28}
}

or simple text

Naqvi, A. (2024). Stata package "ternary" version 1.0. Release date 28 August 2024. https://github.com/asjadnaqvi/stata-ternary.

or see SSC citation (updated once a new version is submitted)

Examples

Users can either copy the files locally

foreach x in NUTS2_edu NUTS2_tourstay NUTS3_gva NUTS3_pop {
	copy "https://github.com/asjadnaqvi/stata-ternary/raw/main/data/`x'.dta" "`x'.dta", replace
}

or load them directly from the server:

use "https://github.com/asjadnaqvi/stata-ternary/blob/main/data/NUTS3_pop.dta?raw=true", clear

Test a basic figure

ternary y15prop y64prop y99prop 

Re arrange the variables:

ternary  y99prop y15prop y64prop

Test ternary with fractions:

ternary y99prop y15prop y64prop, norm(1)

Colors

ternary  y99prop y15prop y64prop, fill

ternary  y99prop y15prop y64prop, fill lcolor(black)

Cuts

ternary y99prop y15prop y64prop, fill cuts(3)

ternary y99prop y15prop y64prop, fill cuts(10)

ternary y99prop y15prop y64prop, fill cuts(6)

Zoom

ternary y99prop y15prop y64prop, fill cuts(6) zoom

ternary y99prop y15prop y64prop, fill cuts(6) zoom msize(2.5) mc(black%60) mlc(white)

ternary y99prop y15prop y64prop, fill cuts(8) zoom msize(2) mc(black%70)  mlc(white) lw(0.08) labcolor(gs6) 

labels (v1.1)

ternary y99prop y15prop y64prop, fill cuts(8) zoom lw(0.08) labcolor(gs6) mlabel(NUTS_ID)

ternary y99prop y15prop y64prop, fill cuts(8) zoom lw(0.08) labcolor(gs6) ///
	mlabel(NUTS_ID)  mlabpos(12)

gen NUTS_ID2 = NUTS_ID if y99prop > 30	

ternary y99prop y15prop y64prop, fill cuts(8) zoom lw(0.08) labcolor(gs6) ///
	mlabel(NUTS_ID2)  mlabpos(12)

Customize colors

ternary y99prop y15prop y64prop, fill zoom cuts(6) mcolor(white%60) ///
	colorB(lime) 

ternary y99prop y15prop y64prop, fill zoom cuts(6) ///
	colorB(red) colorL(green) colorR(blue)

ternary y99prop y15prop y64prop, fill zoom cuts(4) ///
	colorB(red) colorL(green) colorR(blue) mcolor(white%60) mlc(black) msize(3)	

other options

ternary y99prop y15prop y64prop, points zoom cuts(6)

ternary y99prop y15prop y64prop, fill points zoom cuts(6) mlcolor(white)

ternary y99prop y15prop y64prop, points zoom cuts(6) lw(0.05) msize(2.5) mlc(white)

ternary y99prop y15prop y64prop, lines labels zoom cuts(6) msize(2.5) points malpha(80) mlc(white)

ternary y99prop y15prop y64prop, lines labels zoom cuts(6) msize(1.5) 

ternary y99prop y15prop y64prop, lines labels zoom cuts(6) msize(1.5) mlc(black) mc(white%60)

ternary y99prop y15prop y64prop, lines labels zoom cuts(6) msize(2) mlc(black) mc(white%80) lw(0.3) msym(triangle)

Feedback

Please open an issue to report errors, feature enhancements, and/or other requests.

Change log

v1.1 (12 Sep 2024)

  • Added norm() option which can be used to normalize the data to 1 (norm(1)) or 100 (norm(100)).
  • Added marker label options: mlabel(), mlabcolor(), mlabposition(), mlabsize().
  • Better zoom option.
  • Minor code cleanups.

v1.0 (28 Aug 2024)

  • First release.