Skip to content

asjadnaqvi/stata-spider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StataMin issues license Stars version release

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


spider-1

spider v1.33

(02 Jul 2024)

This package provides the ability to draw spiders Stata. It is based on the Spider plots guide on Medium

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.31):

ssc install spider, replace

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

net install spider, from("https://raw.githubusercontent.com/asjadnaqvi/stata-spider/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:

spider var [if] [in], by(var) 
                [ over(var) alpha(num 0-100) rotate(num) smooth(num 0-1) palette(str) range(min max) cuts(num) lwidth(str) msymbol(str) rotatelabel
                  format(fmt) ralabsize(str) ralabcolor(str) ralabangle(str) msize(str) mlwidth(str) displacelab(num) displacespike(num) wrap(num)
                  ccolor(str) cwidth(str) scolor(str) swidth(str) slabsize(str) slabcolor(str) nolegend legpositon(num) legpositon(num) legcolumns(num) legsize(num) 
				  xsize(num) ysize(num) *
                ]

See the help file help spider for details.

The most basic use is as follows:

spider numeric variables, over(category variable)

where numeric variables are a set of variables where each corresponds to a spider plot, and over() defines the categories.

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

or simple text

Naqvi, A. (2024). Stata package "spider" version 1.33. Release date 02 July 2024. https://github.com/asjadnaqvi/stata-spider.

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

Examples

Set up the data:

clear

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

and test the command:

spider index, by(policy) 

spider index, by(policy) over(region)

spider index, by(policy) over(region) alpha(0)

spider index, by(policy) over(region) alpha(0) msym(none)

spider index, by(policy) over(region) alpha(0) msym(square) msize(0.2) ra(0 100)

spider index, by(policy) over(region) alpha(0) rot(30)

spider index, by(policy) over(region) alpha(0) rot(30) rotatelab

Smooth the spiders

spider index if inlist(region,1,6), by(policy) over(region) ra(10 80) cuts(8) alpha(2)

spider index if inlist(region,1,6), by(policy) over(region) ra(10 80) cuts(8) alpha(2) smooth(0)

spider index if inlist(region,1,6), by(policy) over(region) ra(10 80) cuts(8) alpha(2) smooth(0.5)

spider index if inlist(region,1,6), by(policy) over(region) ra(10 80) cuts(8) alpha(2) smooth(1)

Palettes

spider index, by(policy) over(region) smooth(0.1) palette(tol vibrant) lw(0.4) msym(none) alpha(2)

spider index, by(policy) over(region) smooth(0.1) palette(carto Bold) lw(0.4) msym(none) alpha(2)

Customize circles and rays

spider index, by(policy) over(region) ra(10 80) cuts(8) smooth(0.1) cc(eltblue) cw(0.05)

spider index, by(policy) over(region) ra(10 80) cuts(8) smooth(0.1) cc(eltblue) cw(0.05) sc(black) sw(0.1)

spider index, by(policy) over(region) ra(10 80) cuts(8) smooth(0.1) cc(eltblue) cw(0.05) sc(eltblue) sw(0.3) displacelab(20) displacespike(10) rotatelab

Legends and custom dimensions (v1.2)

spider index, by(policy) over(region) smooth(0) alpha(5) xsize(4) ysize(3)

spider index, by(policy) over(region) smooth(0) alpha(5) xsize(4) ysize(3) legpos(3) legcol(1)

Try a different scaling

gen index2 = index / 100

spider index2, by(policy) over(region) ra(0.1 0.8) raformat(%5.1f)  smooth(0) alpha(0) ralabs(2)

Range label options (v1.21)

spider index2, by(policy) over(region) ra(0.1 0.8) raformat(%5.1f) smooth(0) alpha(0) ralabc(blue) ralabs(1.5) ralaba(-90)

Bonus: Valentines day spending spider graph

set scheme white_tableau
graph set window fontface "Abel"

import delim using "https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2024/2024-02-13/gifts_gender.csv", clear

foreach x of varlist spendingcelebrating- giftcards {
	ren `x' y_`x'
}

drop y_spendingcelebrating

reshape long y_, i(gender) j(cat) string

replace cat = "Candy" if cat=="candy"
replace cat = "Clothing" if cat=="clothing"
replace cat = "Evening out" if cat=="eveningout"
replace cat = "Flowers" if cat=="flowers"
replace cat = "Gift cards" if cat=="giftcards"
replace cat = "Greeting cards" if cat=="greetingcards"
replace cat = "Jewelry" if cat=="jewelry"
replace cat = "Spending celebrating" if cat=="spendingcelebrating"


spider y_, by(cat) over(gender) smooth(0.2) alpha(15) lw(0.4) palette(w3 default, select(1 3)) rotatelab ///
	legcol(3) legsize(3) msize(0.1) sc(black) ccolor(gs13) range(0 60) displacelab(10) slabsize(2.2) ///
	title("{fontface Merriweather Bold:Candy crush ♥}", size(7) color(cranberry))  ///
	subtitle("(Percentage positive respones by spending category)", size(2)) ///
	note("Source: TidyTuesday, 14th Feb 2024.", size(1.5))

Feedback

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

Change log

v1.33 (02 Jul 2024)

  • Fixed a minor error where numeric over() and by() were not being labeled correctly.

v1.32 (11 Jun 2024)

  • Added wrap() to wrap labels.

v1.31 (11 May 2024)

  • changed raformat() to just format() to standardize the use across packages.
  • format() default improved to show decimals.
  • Checks added for by() and over() to have minimum number of accepted categories.
  • Stata default passthru options improved.

v1.3 (16 Feb 2024)

  • Complete rework of the package to take in the data in the long form. While this might be convinient for users who were using it for wide data, the newer version handle the data and labels better and is faster. The wide option might still be added back in later. Please note that change in the by() and over() options.
  • rotatelabel option added.
  • Better legend controls. Please make sure value labels are properly defined that are passed on to legends.

v1.23 (12 Nov 2023)

  • Added support for slabcolor() (requested by Christian Gessinger).
  • Added saving().

v1.22 (07 Jul 2023)

  • Fixed a bug where labeled over() categories were not passing correctly (reported by Kamala Kaghoma).

v1.21 (10 Jun 2023)

  • Two options added for range labels: ralabcolor(), ralabangle().

v1.2 (20 May 2023)

  • Several legend options added (requested by Marc Kaulisch). These include nolegend, legendpos(), legendsize(), legendcol().
  • xsize() and ysize() added to allow users to control the dimensions.
  • Minor code cleanups.
  • Help file cleanup.

v1.1 (24 Dec 2022)

  • Fixed some bugs.
  • Better checks for merges.

v1.0 (13 Oct 2022)

  • First release