Skip to content

Commit

Permalink
v1.3 fix #12 fix #11 fix #9 fix #4 fix #3 fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
asjadnaqvi committed Feb 17, 2024
1 parent ce692a3 commit 216ba23
Show file tree
Hide file tree
Showing 36 changed files with 258 additions and 155 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 ``spider''"
version: 1.23
date-released: 2023-11-12
version: 1.3
date-released: 2024-02-16
url: "https://github.com/asjadnaqvi/stata-spider"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Asjad Naqvi
Copyright (c) 2024 Asjad Naqvi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
151 changes: 109 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

---

# spider v1.23
(12 Nov 2023)
# spider v1.3
(16 Feb 2024)

This package provides the ability to draw spiders Stata. It is based on the [Spider plots](https://medium.com/the-stata-guide/stata-graphs-spider-plots-613808b51f73) guide on Medium

Expand All @@ -24,7 +24,7 @@ The SSC version (**v1.23**):
ssc install spider, replace
```

Or it can be installed from GitHub (**v1.23**):
Or it can be installed from GitHub (**v1.3**):

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

The syntax for the latest version is as follows:

```
spider varlist [if] [in], over(cat var)
[ alpha(num 0-100) rotate(num) smooth(num 0-1) palette(str)
range(val1 val2) cuts(num) lwidth(str) msymbol(str)
```stata
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
raformat(fmt) ralabsize(str) ralabcolor(str) ralabangle(str)
msize(str) mlwidth(str) displacelab(num) displacespike(num)
ccolor(str) cwidth(str) scolor(str) swidth(str) slabsize(str)
nolegend legpositon(num) legpositon(num) legcolumns(num) legsize(num)
title(str) subtitle(str) note(str) scheme(str) xsize(num) ysize(num) name(str) saving(str) ]
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)
title(str) subtitle(str) note(str) scheme(str) name(str) saving(str)
]
```

See the help file `help spider` for details.
Expand All @@ -89,7 +90,7 @@ Set up the data:
```
clear
use "https://github.com/asjadnaqvi/stata-spider/blob/main/data/spider_test.dta?raw=true", clear
use "https://github.com/asjadnaqvi/stata-spider/blob/main/data/spider_data2.dta?raw=true", clear
drop index_AUS index_LAC // can also keep these
Expand All @@ -98,86 +99,113 @@ gen year = year(date)


```
spider index*, over(policy)
spider index, by(policy)
```

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

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

<<<<<<< Updated upstream
<img src="/figures/spider2.png" width="100%">
=======
<img src="/figures/spider1_2.png" width="100%">
>>>>>>> Stashed changes
```
spider index*, over(policy) alpha(0) msym(none)
spider index, by(policy) over(region) alpha(0)
```

<<<<<<< Updated upstream
<img src="/figures/spider3.png" width="100%">
=======
<img src="/figures/spider2.png" width="100%">
>>>>>>> Stashed changes
```
spider index*, over(policy) alpha(0) msym(none) ra(0 100)
spider index, by(policy) over(region) alpha(0) msym(none)
```

<<<<<<< Updated upstream
<img src="/figures/spider4.png" width="100%">
=======
<img src="/figures/spider3.png" width="100%">
>>>>>>> Stashed changes
```
spider index*, over(policy) alpha(0) msym(none) ra(0 100) cuts(5)
spider index, by(policy) over(region) alpha(0) msym(square) msize(0.2) ra(0 100)
```

<<<<<<< Updated upstream
<img src="/figures/spider5.png" width="100%">
=======
<img src="/figures/spider4.png" width="100%">
>>>>>>> Stashed changes
```
spider index*, over(policy) alpha(0) msym(none) ra(20 70) cuts(6)
spider index, by(policy) over(region) alpha(0) rot(30)
```

<<<<<<< Updated upstream
<img src="/figures/spider5_1.png" width="100%">
=======
<img src="/figures/spider5.png" width="100%">
>>>>>>> Stashed changes
```
spider index*, over(policy) alpha(0) msym(none) ra(20 70) cuts(6) rot(45)
spider index, by(policy) over(region) alpha(0) rot(30) rotatelab
```

<<<<<<< Updated upstream
<img src="/figures/spider5_2.png" width="100%">
=======
<img src="/figures/spider5_1.png" width="100%">
>>>>>>> Stashed changes
```
spider index* if year==2021, over(policy) alpha(0) msym(none) ra(0 100) cuts(5)
```

<<<<<<< Updated upstream
<img src="/figures/spider6.png" width="100%">

```
spider index* if year==2021, over(policy) msym(Oh) lw(0.4) ms(0.4) ra(0 100)
```

<img src="/figures/spider6_1.png" width="100%">
=======
>>>>>>> Stashed changes
### Smooth the spiders

```
spider index*, over(policy) ra(10 80) cuts(8) smooth(0)
spider index if inlist(region,1,6), by(policy) over(region) ra(10 80) cuts(8) alpha(2)
spider index*, over(policy) ra(10 80) cuts(8) smooth(0.5)
spider index if inlist(region,1,6), by(policy) over(region) ra(10 80) cuts(8) alpha(2) smooth(0)
spider index*, over(policy) ra(10 80) cuts(8) smooth(1)
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)
```

<img src="/figures/spider7_1.png" height="250"><img src="/figures/spider7_2.png" height="250"><img src="/figures/spider7_3.png" height="250">
<img src="/figures/spider7.png" height="250"><img src="/figures/spider7_1.png" height="250"><img src="/figures/spider7_2.png" height="250"><img src="/figures/spider7_3.png" height="250">

### Palettes

```
spider index*, over(policy) ra(10 80) cuts(8) smooth(0.1) palette(tol vibrant) lw(0.4) ms(0.6) alpha(2)
spider index, by(policy) over(region) smooth(0.1) palette(tol vibrant) lw(0.4) msym(none) alpha(2)
```

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

```
spider index*, over(policy) ra(10 80) cuts(8) smooth(0.1) palette(carto Bold) lw(0.4) ms(0.6) alpha(2)
spider index, by(policy) over(region) smooth(0.1) palette(carto Bold) lw(0.4) msym(none) alpha(2)
```

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


<<<<<<< Updated upstream
Pass specific colors:

```
Expand All @@ -186,38 +214,40 @@ spider index*, over(policy) ra(10 80) cuts(8) smooth(0.1) palette(CET C1, select

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

=======
>>>>>>> Stashed changes
### Customize circles and rays


```
spider index*, over(policy) 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)
```

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

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

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

```
spider index*, over(policy) ra(10 80) cuts(8) smooth(0.1) cc(eltblue) cw(0.05) sc(eltblue) sw(0.3) displacelab(20) displacespike(10)
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
```

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

### Legends and custom dimensions (v1.2)

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

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

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

<img src="/figures/spider9_5.png" width="100%">
Expand All @@ -226,22 +256,59 @@ spider index*, over(policy) xsize(4) ysize(3) legpos(3) legcol(1)
### Try a different scaling

```
foreach x of varlist index_* {
replace `x' = `x' / 100
}
gen index2 = index / 100
spider index*, over(policy) ra(0.1 0.7) cuts(4) raformat(%5.1f) ralabs(2) smooth(0) alpha(0)
spider index2, by(policy) over(region) ra(0.1 0.8) raformat(%5.1f) smooth(0) alpha(0) ralabs(2)
```

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

### Range label options (v1.21)

```
spider index* if year==2021, over(policy) msym(Oh) lw(0.4) ms(0.4) ra(0 100) ralabc(blue) ralabs(2) ralaba(45)
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)
```

<img src="/figures/spider11.png" width="100%">
<<<<<<< Updated upstream
=======


### 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))
```

<img src="/figures/valentines2024.png" width="100%">
>>>>>>> Stashed changes

## Feedback
Expand All @@ -251,6 +318,11 @@ Please open an [issue](https://github.com/asjadnaqvi/stata-spider/issues) to rep

## Change log

**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()`.
Expand All @@ -273,8 +345,3 @@ Please open an [issue](https://github.com/asjadnaqvi/stata-spider/issues) to rep

**v1.0 (13 Oct 2022)**
- First release





Binary file added data/spider2.dta
Binary file not shown.
Binary file removed data/spider_test.dta
Binary file not shown.
Binary file modified figures/spider1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figures/spider1_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed figures/spider4_1.png
Binary file not shown.
Binary file modified figures/spider5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider5_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed figures/spider5_2.png
Binary file not shown.
Binary file removed figures/spider6.png
Binary file not shown.
Binary file removed figures/spider6_1.png
Binary file not shown.
Binary file removed figures/spider6_2.png
Binary file not shown.
Binary file modified figures/spider7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider7_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider7_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider7_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider8_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider8_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed figures/spider8_3.png
Binary file not shown.
Binary file modified figures/spider9_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider9_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider9_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider9_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/spider9_5.png
Binary file added figures/valentines2024.png
Loading

0 comments on commit 216ba23

Please sign in to comment.