diff --git a/README.md b/README.md
index 125e445..a81cb7a 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
![StataMin](https://img.shields.io/badge/stata-2015-blue) ![issues](https://img.shields.io/github/issues/asjadnaqvi/stata-bimap) ![license](https://img.shields.io/github/license/asjadnaqvi/stata-bimap) ![Stars](https://img.shields.io/github/stars/asjadnaqvi/stata-bimap) ![version](https://img.shields.io/github/v/release/asjadnaqvi/stata-bimap) ![release](https://img.shields.io/github/release-date/asjadnaqvi/stata-bimap)
-# bimap v1.2
+# bimap v1.3
This package provides the ability to draw bi-variate maps in Stata. It is based on the [Bi-variate maps Guide](https://medium.com/the-stata-guide/stata-graphs-bi-variate-maps-b1e96dd4c2be) that I released in December 2021.
@@ -10,12 +10,12 @@ This package provides the ability to draw bi-variate maps in Stata. It is based
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 package can be installed from SSC (**v1.0**):
+The package can be installed from SSC (**v1.2**):
```
ssc install bimap, replace
```
-Or it can be installed from GitHub (**v1.2**):
+Or it can be installed from GitHub (**v1.3**):
```
net install bimap, from("https://raw.githubusercontent.com/asjadnaqvi/stata-bimap/main/installation/") replace
@@ -53,12 +53,12 @@ This command is a wrapper for `spmap` and assumes that you have shapefiles in St
## Syntax
-The syntax for **v1.2** is as follows:
+The syntax for **v1.3** is as follows:
```
bimap vary varx [if] [in], cut(option) palette(option)
- [ count values ocolor(str) osize(str) ndocolor(str) ndsize(str) ndocolor(str)
+ [ count percent values ocolor(str) osize(str) ndocolor(str) ndsize(str) ndocolor(str)
polygon(str) line(str) point(str) label(str)
textx(string) texty(str) TEXTLABSize(num) TEXTSize(num) BOXsize(num) xscale(num) yscale(num)
title(str) subtitle(str) note(str) name(srt) scheme(str) ]
@@ -151,20 +151,32 @@ bimap share_hisp share_afam using usa_county_shp_clean, cut(equal) palette(pinkg
+### Palettes
+
```
-bimap share_hisp share_afam using usa_county_shp_clean, cut(pctile) palette(purpleyellow) ///
- title("My first bivariate map") subtitle("Made with Stata") note("Data from US Census")
+local i = 1
+
+foreach x in pinkgreen bluered greenblue purpleyellow yellowblue orangeblue brew1 brew2 brew3 census {
+ bimap share_hisp share_afam using usa_county_shp_clean, cut(pctile) palette(`x') percent title("Scheme: `x'")
+ graph export bimap3_`i'.png, replace wid(2000)
+ local i = `i' + 1
+}
```
-
+
+
+
+
+
+### Advanced examples
```
bimap share_asian share_afam using usa_county_shp_clean, cut(pctile) palette(bluered) ///
title("{fontface Arial Bold:My first bivariate map}") subtitle("Made with Stata") note("Data from the US Census Bureau.") ///
- textx("Share of African Americans") texty("Share of Asians") texts(3.5) textlabs(3) values count ///
- ocolor() osize(none) ///
- polygon(data("usa_state_shp_clean") ocolor(white) osize(0.3))
+ textx("Share of African Americans") texty("Share of Asians") texts(3.5) textlabs(3) values count ///
+ ocolor() osize(none) ///
+ polygon(data("usa_state_shp_clean") ocolor(white) osize(0.3))
```
@@ -193,18 +205,16 @@ bimap share_asian share_hisp using usa_county_shp_clean, cut(pctile) palette(or
-### Adding other layers to the bimap
-
Since `bimap` is a wrapper of `spmap`, we can pass information for other layers as well including dots. Below we use the file we saved in the first step to plot the population of counties:
```
-bimap share_hisp share_afam using usa_county_shp_clean, cut(pctile) palette(pinkgreen) ///
+bimap share_hisp share_afam using usa_county_shp_clean, cut(pctile) palette(pinkgreen) percent ///
title("{fontface Arial Bold:My first bivariate map}") subtitle("Made with Stata") ///
note("Data from the US Census Bureau. Counties with population > 100k plotted as proportional dots.", size(1.8)) ///
- textx("Share of African Americans") texty("Share of Hispanics") texts(3.5) textlabs(3) values count ///
- ocolor() osize(none) ///
+ textx("Share of African Americans") texty("Share of Hispanics") texts(3.5) textlabs(3) values ///
+ osize(none) ///
polygon(data("usa_state_shp_clean") ocolor(white) osize(0.3)) ///
- point(data("usa_county2") x(_CX) y(_CY) select(keep if tot_pop>100000) proportional(tot_pop) psize(absolute) fcolor(lime%85) ocolor(black) osize(0.12) size(0.9) )
+ point(data("usa_county2") x(_CX) y(_CY) select(keep if tot_pop>100000) proportional(tot_pop) psize(absolute) fcolor(lime%85) ocolor(black) osize(0.12) size(0.9))
```
@@ -216,6 +226,11 @@ Please open an [issue](https://github.com/asjadnaqvi/stata-bimap/issues) to repo
## Versions
+**v1.3 (26 May 2022)**
+- Percent option added to legend to show box share (thanks to Kit Baum).
+- Legend corner label made lighter for visibility.
+- Four special use palettes added: `brew1`, `brew2`, `brew3`, `brew4`, `census`.
+
**v1.2 (29 Apr 2022)**
- Fixed a bug in cut-off groupings (thanks to Ruth Watkinson).
- Error in how cut-off values are collected is fixed.
@@ -228,7 +243,6 @@ Please open an [issue](https://github.com/asjadnaqvi/stata-bimap/issues) to repo
- Errors in ado file corrected.
- Help file was missing a couple of options.
-
**v1.0 (08 Apr 2022)**
- Public release.
diff --git a/figures/bimap2_1_1.png b/figures/bimap2_1_1.png
new file mode 100644
index 0000000..a55da72
Binary files /dev/null and b/figures/bimap2_1_1.png differ
diff --git a/figures/bimap3_1.png b/figures/bimap3_1.png
new file mode 100644
index 0000000..f5671fd
Binary files /dev/null and b/figures/bimap3_1.png differ
diff --git a/figures/bimap3_10.png b/figures/bimap3_10.png
new file mode 100644
index 0000000..df54600
Binary files /dev/null and b/figures/bimap3_10.png differ
diff --git a/figures/bimap3_2.png b/figures/bimap3_2.png
new file mode 100644
index 0000000..5f8ee4a
Binary files /dev/null and b/figures/bimap3_2.png differ
diff --git a/figures/bimap3_3.png b/figures/bimap3_3.png
new file mode 100644
index 0000000..b0934c4
Binary files /dev/null and b/figures/bimap3_3.png differ
diff --git a/figures/bimap3_4.png b/figures/bimap3_4.png
new file mode 100644
index 0000000..baf2d50
Binary files /dev/null and b/figures/bimap3_4.png differ
diff --git a/figures/bimap3_5.png b/figures/bimap3_5.png
new file mode 100644
index 0000000..7f1f80f
Binary files /dev/null and b/figures/bimap3_5.png differ
diff --git a/figures/bimap3_6.png b/figures/bimap3_6.png
new file mode 100644
index 0000000..5eca4ab
Binary files /dev/null and b/figures/bimap3_6.png differ
diff --git a/figures/bimap3_7.png b/figures/bimap3_7.png
new file mode 100644
index 0000000..42f0027
Binary files /dev/null and b/figures/bimap3_7.png differ
diff --git a/figures/bimap3_8.png b/figures/bimap3_8.png
new file mode 100644
index 0000000..31e176f
Binary files /dev/null and b/figures/bimap3_8.png differ
diff --git a/figures/bimap3_9.png b/figures/bimap3_9.png
new file mode 100644
index 0000000..26fc0ba
Binary files /dev/null and b/figures/bimap3_9.png differ
diff --git a/figures/bimap5.png b/figures/bimap5.png
new file mode 100644
index 0000000..d81a8be
Binary files /dev/null and b/figures/bimap5.png differ
diff --git a/figures/bimap8.png b/figures/bimap8.png
index 9f83740..422c5f9 100644
Binary files a/figures/bimap8.png and b/figures/bimap8.png differ
diff --git a/figures/bimap_banner.png b/figures/bimap_banner.png
deleted file mode 100644
index 11216dc..0000000
Binary files a/figures/bimap_banner.png and /dev/null differ
diff --git a/figures/bimap_banner2.png b/figures/bimap_banner2.png
deleted file mode 100644
index d1a6261..0000000
Binary files a/figures/bimap_banner2.png and /dev/null differ
diff --git a/installation/bimap.ado b/installation/bimap.ado
index dc76a8f..26a354f 100644
--- a/installation/bimap.ado
+++ b/installation/bimap.ado
@@ -1,5 +1,9 @@
-*! Bimap Naqvi v1.2 05 May 2022. category cut-offs, counts, error checks, bug fixes, new palettes
-* v1.1 14 Apr 2022. Stable release
+*! bimap v1.3
+*! Asjad Naqvi (asjadnaqvi@gmail.com)
+*! 26 May 2022: added percent option. Color range fixes. New schemes. label fixes
+
+* v1.2: 05 May 2022. Category cut-offs, counts, error checks, bug fixes, new palettes
+* v1.1: 14 Apr 2022. Stable release
**********************************
* Step-by-step guide on Medium *
@@ -20,7 +24,7 @@ version 15
syntax varlist(min=2 max=2 numeric) [if] [in] using/ , ///
cut(string) palette(string) ///
- [ count BOXsize(real 8) textx(string) texty(string) xscale(real 30) yscale(real 100) TEXTLABSize(real 2) TEXTSize(real 2.5) values ] ///
+ [ count percent BOXsize(real 8) textx(string) texty(string) xscale(real 30) yscale(real 100) TEXTLABSize(real 2) TEXTSize(real 2.5) values ] ///
[ polygon(passthru) line(passthru) point(passthru) label(passthru) ] ///
[ ocolor(string) osize(string) ] ///
[ ndocolor(string) ndsize(string) ndfcolor(string) ] ///
@@ -101,15 +105,10 @@ qui {
}
- *fillin `cat_`var1'' `cat_`var2'' // rectangularize for correct assignment with group
sort `cat_`var1'' `cat_`var2''
tempvar grp_cut
- *egen `grp_cut' = group(`cat_`var1'' `cat_`var2'')
-
- *drop if _fillin==1 // drop the groups we don't actually have
- *drop _fillin
gen `grp_cut' = .
@@ -154,6 +153,12 @@ qui {
// grp order: 1 = 1 1, 2 = 1 2, 3 = 1 3, 4 = 2 1, 5 = 2 2, 6 = 2 3, 7 = 3 1, 8 = 3 2, 9 = 3 3
+ if "`count'" != "" & "`percent'" != "" {
+ di as error "Please specify either {it:count} or {it:percent} option."
+ exit
+ }
+
+
if "`count'" != "" {
forval i = 1/3 {
@@ -164,12 +169,27 @@ qui {
}
}
-
+
+ if "`percent'" != "" {
+
+ count if `cat_`var1''!=. & `cat_`var2''!=.
+ local grsum = `r(N)'
+
+ forval i = 1/3 {
+ forval j = 1/3 {
+ count if `cat_`var1''==`j' & `cat_`var2''==`i'
+ local grsize`i'`j' = (`r(N)' / `grsum') * 100
+ local grsize`i'`j' : di %3.1f `grsize`i'`j''
+ }
+ }
+
+
+ }
// from spmap
if "`palette'" != "" {
- local LIST "pinkgreen bluered greenblue purpleyellow yellowblue orangeblue"
+ local LIST "pinkgreen bluered greenblue purpleyellow yellowblue orangeblue brew1 brew2 brew3 census"
local LEN = length("`palette'")
local check = 0
foreach z of local LIST {
@@ -179,7 +199,7 @@ qui {
}
if !`check' {
- di in yellow "Wrong palette specified. The supported palettes are {ul:pinkgreen}, {ul:bluered}, {ul:greenblue}, {ul:purpleyellow}, {ul:yellowblue}, {ul:orangeblue}."
+ di in yellow "Wrong palette specified. The supported palettes are {ul:pinkgreen}, {ul:bluered}, {ul:greenblue}, {ul:purpleyellow}, {ul:yellowblue}, {ul:orangeblue}, {ul:brew1}, {ul:brew2}, {ul:brew3}, {ul:census}."
exit 198
}
}
@@ -206,7 +226,24 @@ qui {
if "`palette'" == "orangeblue" { // from ArcGIS
local color #fef1e4 #97d0e7 #18aee5 #fab186 #b0988c #407b8f #f3742d #ab5f37 #5c473d
- }
+ }
+
+ if "`palette'" == "brew1" {
+ local color #f37300 #fe9aa6 #f0047f #cce88b #e6e6e6 #cd9acc #008837 #9ac9d5 #5a4da4
+ }
+
+ if "`palette'" == "brew2" {
+ local color #c3b3d8 #7b67ab #240d5e #e6e6e6 #bfbfbf #7f7f7f #ffcc80 #f35926 #b30000
+ }
+
+ if "`palette'" == "brew3" {
+ local color #cce8d7 #80c39b #008837 #cedced #85a8d0 #0a50a1 #fbb4d9 #f668b3 #d60066
+ }
+
+ if "`palette'" == "census" {
+ local color #fffdef #e6f1df #d2e4f6 #fef3a9 #bedebc #a1c8ea #efd100 #4eb87b #007fc4
+ }
+
if "`polygon'" == "" {
local polyadd
@@ -248,7 +285,7 @@ qui {
egen x = seq(), t(3)
- if "`count'" != "" {
+ if "`count'" != "" | "`percent'" != "" {
gen mycount = .
local x = 1
@@ -258,20 +295,13 @@ qui {
local x = `x' + 1
}
}
-
-
- *forval i = 1/9 {
- * replace mycount = `grsize`i'' in `i'
- *}
-
+
local marksym mycount
}
-
cap drop spike*
-
if "`textx'" == "" {
local labx = "`var1'"
}
@@ -288,27 +318,27 @@ qui {
// arrows
- gen spike1_x1 = 0.35 in 1
- gen spike1_x2 = 3.6 in 1
- gen spike1_y1 = 0.35 in 1
- gen spike1_y2 = 0.35 in 1
- gen spike1_m = "`labx'" in 1
+ gen spike1_x1 = 0.35 in 1
+ gen spike1_x2 = 3.6 in 1
+ gen spike1_y1 = 0.35 in 1
+ gen spike1_y2 = 0.35 in 1
+ gen spike1_m = "`labx'" in 1
- gen spike2_y1 = 0.35 in 1
- gen spike2_y2 = 3.6 in 1
- gen spike2_x1 = 0.35 in 1
- gen spike2_x2 = 0.35 in 1
- gen spike2_m = "`laby'" in 1
+ gen spike2_y1 = 0.35 in 1
+ gen spike2_y2 = 3.6 in 1
+ gen spike2_x1 = 0.35 in 1
+ gen spike2_x2 = 0.35 in 1
+ gen spike2_m = "`laby'" in 1
// ticks
gen xvalx = .
gen xvaly = .
gen xvaln = .
- replace xvaly = 0.36 in 1/3
- replace xvalx = 0.8 in 1
- replace xvalx = 1.8 in 2
- replace xvalx = 2.8 in 3
+ replace xvaly = 0.36 in 1/3
+ replace xvalx = 0.8 in 1
+ replace xvalx = 1.8 in 2
+ replace xvalx = 2.8 in 3
replace xvaln = `var11' in 1
replace xvaln = `var12' in 2
@@ -319,10 +349,10 @@ qui {
gen yvaly = .
gen yvaln = .
- replace yvalx = 0.33 in 1/3
- replace yvaly = 1.1 in 1
- replace yvaly = 2.1 in 2
- replace yvaly = 3.1 in 3
+ replace yvalx = 0.33 in 1/3
+ replace yvaly = 1.1 in 1
+ replace yvaly = 2.1 in 2
+ replace yvaly = 3.1 in 3
replace yvaln = `var21' in 1
replace yvaln = `var22' in 2
@@ -335,12 +365,12 @@ qui {
gen laby = .
gen labn = ""
- replace labx = 2 in 1
- replace laby = 0 in 1
+ replace labx = 2 in 1
+ replace laby = 0 in 1
replace labn = "`labx'" in 1
- replace labx = 0 in 2
- replace laby = 3 in 2
+ replace labx = 0 in 2
+ replace laby = 3 in 2
replace labn = "`laby'" in 2
@@ -369,8 +399,18 @@ qui {
foreach x of local xlvl {
foreach y of local ylvl {
- local boxes `boxes' (scatter y x if x==`x' & y==`y', mlab("`marksym'") mlabpos(0) msymbol(square) msize(`boxsize') mc("`color`x'`y''")) ///
+ if (`x'==3 & `y'==3) { // | (`x'==3 & `y'==2) | (`x'==2 & `y'==3)
+ local boxes `boxes' (scatter y x if x==`x' & y==`y', mlab("`marksym'") mlabpos(0) mlabc(gs13) msymbol(square) msize(`boxsize') mc("`color`x'`y''")) ///
+
+ }
+
+ else {
+ local boxes `boxes' (scatter y x if x==`x' & y==`y', mlab("`marksym'") mlabpos(0) mlabc(black) msymbol(square) msize(`boxsize') mc("`color`x'`y''")) ///
+
+ }
+
+
}
}
diff --git a/installation/bimap.pkg b/installation/bimap.pkg
index ed94741..e142424 100644
--- a/installation/bimap.pkg
+++ b/installation/bimap.pkg
@@ -1,4 +1,4 @@
-v 1.2
+v 1.3
d {bf:BIMAP}: Bi-variate maps
d
d
@@ -9,7 +9,7 @@ d KW: graphs
d KW: map
d KW: bivariate map
d
-d This version: 05 May 2022
+d This version: 26 May 2022
d First version: 08 Apr 2022
d License: MIT
d
diff --git a/installation/bimap.sthlp b/installation/bimap.sthlp
index 91fb8fa..d12b695 100644
--- a/installation/bimap.sthlp
+++ b/installation/bimap.sthlp
@@ -1,7 +1,7 @@
{smcl}
-{* 05May2022}{...}
+{* 26May2022}{...}
{hi:help bimap}{...}
-{right:{browse "https://github.com/asjadnaqvi/stata-bimap":bimap v1.2 (GitHub)}}
+{right:{browse "https://github.com/asjadnaqvi/stata-bimap":bimap v1.3 (GitHub)}}
{hline}
@@ -16,7 +16,7 @@ The {cmd:bimap} command is a wrapper for {stata help spmap:spmap}. Therefore it
{p 8 15 2}
{cmd:bimap} {it:vary varx} {ifin}, {cmd:cut}({it:option}) {cmd:palette}({it:option})
- {cmd:[} {cmd:count} {cmd:values} {cmd:ocolor}({it:str}) {cmd:osize}({it:str}) {cmd:ndocolor}({it:str}) {cmd:ndfcolor}({it:str})
+ {cmd:[} {cmd:count} {cmd:percent} {cmd:values} {cmd:ocolor}({it:str}) {cmd:osize}({it:str}) {cmd:ndocolor}({it:str}) {cmd:ndfcolor}({it:str})
{cmd:polygon}({it:options}) {cmd:line}({it:options}) {cmd:point}({it:options}) {cmd:label}({it:options})
{cmd:textx}({it:string}) {cmd:texty}({it:str}) {cmdab:textlabs:ize}({it:num}) {cmdab:texts:ize}({it:num}) {cmdab:box:size}({it:num}) {cmd:xscale}({it:num}) {cmd:yscale}({it:num})
{cmd:title}({it:str}) {cmd:subtitle}({it:str}) {cmd:note}({it:str}) {cmd:name}({it:str}) {cmd:scheme}({it:str}) {cmd:]}
@@ -34,7 +34,8 @@ The options are described as follows:
{p2coldent : {opt cut(option)}}Here {cmd:cut} can take on two values: {ul:{it:pctile}} for percentiles or terciles in this case,
OR {ul:{it:equal}} for equal intervals. These cutoff values can be displayed using the {cmd:values} option. See below.{p_end}
-{p2coldent : {opt palette(option)}}Palette options for bi-variate maps are: {ul:{it:pinkgreen}}, {ul:{it:bluered}}, {ul:{it:greenblue}}, {ul:{it:purpleyellow}}, {ul:{it:yellowblue}}, {ul:{it:orangeblue}}.{p_end}
+{p2coldent : {opt palette(option)}}Palette options for bi-variate maps are: {ul:{it:pinkgreen}}, {ul:{it:bluered}}, {ul:{it:greenblue}}, {ul:{it:purpleyellow}}, {ul:{it:yellowblue}}, {ul:{it:orangeblue}},
+{ul:{it:brew1}}, {ul:{it:brew2}}, {ul:{it:brew3}}, {ul:{it:census}}. See {browse "https://github.com/asjadnaqvi/stata-bimap":GitHub} for palette examples.{p_end}
{p2coldent : {opt osize(string)}}Line width of polygons. Same as in {cmd:spmap}. Default value is {it:0.02}. Also applied to polygons with no data.{p_end}
@@ -52,7 +53,7 @@ OR {ul:{it:equal}} for equal intervals. These cutoff values can be displayed usi
{p 4 4 2}
{it:{ul:Legend options}:}
-{p2coldent : {opt count}}Display the count of categories in each box in the bi-variate map legend.{p_end}
+{p2coldent : {opt count} {it:or} {opt percent}}Display the count or percent of categories in each box in the bi-variate map legend.{p_end}
{p2coldent : {opt values}}Display the cut off values in the bi-variate map legend.{p_end}
@@ -87,7 +88,7 @@ Even if you have the packages installed, please check for updates: {stata ado up
{title:Examples}
-- Download the files from the {browse "https://github.com/asjadnaqvi/stata-bimap/tree/main/GIS":bimap GitHub repository} and copy them in a directory.
+Download the files from the {browse "https://github.com/asjadnaqvi/stata-bimap/tree/main/GIS":bimap GitHub repository} and copy them in a directory.
use usa_county, clear
destring _all, replace
@@ -117,12 +118,15 @@ bimap share_asian share_afam using usa_county_shp_clean, cut(pctile) palette(blu
ocolor() osize(none) ///
polygon(data("usa_state_shp_clean") ocolor(white) osize(0.3))
+
+Additional examples on {browse "https://github.com/asjadnaqvi/stata-bimap":GitHub}.
+
{hline}
{title:Package details}
-Version : {bf:bimap} v1.2
-This release : 05 May 2022
+Version : {bf:bimap} v1.3
+This release : 26 May 2022
First release: 08 Apr 2022
Repository : {browse "https://github.com/asjadnaqvi/stata-bimap":GitHub}
Keywords : Stata, graph, bi-variate, map
@@ -133,10 +137,14 @@ E-mail : asjadnaqvi@gmail.com
Twitter : {browse "https://twitter.com/AsjadNaqvi":@AsjadNaqvi}
+
{title:Acknowledgements}
-Ruth Watkinson found an error in the grouping code. Pierre-Henri Bono suggested passthru options for {cmd:spmap}.
+Ruth Watkinson found an error in the grouping code. Pierre-Henri Bono suggested passthru options for {cmd:spmap}. Kit Baum requested the {it:percent} option and fixes to label colors.
+
+{title:Feedback}
+If you find bugs or have feature requests, then please open an {browse "https://github.com/asjadnaqvi/stata-bimap/issues":issue} on GitHub.
{title:References}