asjadnaqvi / stata-bumpline

A Stata package for bump line charts
MIT License
3 stars 0 forks source link
bump line package stata

bumpline-1

StataMin issues license Stars version release


Installation | Syntax| Citation guidelines | Examples | Feedback | Change log


bumpline v1.21

(11 June 2024)

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.

SSC (v1.21):

ssc install bumpline, replace

GitHub (v1.21):

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

The palettes package is required to run this command:

ssc install palettes, replace
ssc install colrspace, replace

Even if you have these packages installed, please check for updates: 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:

bumpline y x [if] [in], by(varname) 
                [ top(num) select(any|last) smooth(num) palette(str) labcond(str) offset(num)
                  lwidth(str) labsize(str) xlabsize(str) ylabsize(str) xlabangle(str) 
                  msymbol(str) msize(str) mlabsize(str) mlwidth(str) wrap(num) * ]

See the help file help bumpline for details.

The most basic use is as follows:

bumparea y x, by(group)

where y is a numerical variable we want to plot and x is the time dimension. Both need to be numeric. The by() is the category variable.

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{bumpline,
   author = {Naqvi, Asjad},
   title = {Stata package ``bumpline''},
   url = {https://github.com/asjadnaqvi/stata-bumpline},
   version = {1.21},
   date = {2024-06-11}
}

or simple text

Naqvi, A. (2024). Stata package "bumpline" version 1.21. Release date 11 June 2024. https://github.com/asjadnaqvi/stata-bumpline.

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

Examples

Load the Stata dataset

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

drop if iso_code==""

// keep a random set of years
keep if inlist(year, 1990, 1992, 1995, 2000, 2005, 2007, 2010, 2013, 2016, 2019)

Let's test the bumpline command:

bumpline total_ghg year, by(country)
bumpline total_ghg year, by(country) top(10) ///
    xsize(2) ysize(1) 
bumpline total_ghg year, by(country) select(last) top(10) ///
    xsize(2) ysize(1) 

Smooth

bumpline total_ghg year, by(country) top(10) ///
    smooth(1) xsize(2) ysize(1) 
bumpline total_ghg year, by(country) top(10) ///
    smooth(8) xsize(2) ysize(1)     

top lists

bumpline total_ghg year, by(country) top(10) ///
    top(15) xsize(2) ysize(1)   
bumpline total_ghg year, by(country) top(10) ///
    top(20) xsize(2) ysize(1)   

Palettes

bumpline total_ghg year, by(country) top(10) ///
    palette(CET L20) xsize(2) ysize(1) 
bumpline total_ghg year, by(country) top(10) ///
    palette(viridis) xsize(2) ysize(1) 
bumpline total_ghg year, by(country) top(10) ///
    palette(reds, reverse) xsize(2) ysize(1)    

Lines and symbols

bumpline total_ghg year, by(country) top(10) ///
    lw(1.4) xsize(2) ysize(1)
bumpline total_ghg year, by(country) top(10) ///
    lw(1.2) msym(square) msize(1.3) xsize(2) ysize(1)   

all together

bumpline total_ghg year, by(country) ///    
smooth(4) top(30) palette(CET L19, reverse) ///
    lw(0.5) msym(square) mlwid(0.3) msize(1.1) xlaba(45) offset(20)  ///
    title("Top 10 countries by annual GHG emissions", size(6)) ///
            note("Source: OWID.") ///
            xsize(2) ysize(1) 

Feedback

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

Change log

v1.21 (11 Jun 2024)

v1.2 (10 Feb 2024)

v1.1 (28 May 2023)

v1.0 (10 Apr 2023)