Skip to content

Commit

Permalink
v1.55
Browse files Browse the repository at this point in the history
  • Loading branch information
asjadnaqvi committed Jun 11, 2024
1 parent 20da6f6 commit a3c82e6
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 22 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 ``treemap''"
version: 1.54
date-released: 2024-04-20
version: 1.55
date-released: 2024-06-10
url: "https://github.com/asjadnaqvi/stata-treemap"
41 changes: 36 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

---

# treemap v1.54
(20 Apr 2024)
# treemap v1.55
(10 Jun 2024)

This package provides the ability to draw treemaps Stata.

Expand All @@ -29,7 +29,7 @@ The SSC version (**v1.54**):
ssc install treemap, replace
```

Or it can be installed from GitHub (**v1.54**):
Or it can be installed from GitHub (**v1.55**):

```stata
net install treemap, from("https://raw.githubusercontent.com/asjadnaqvi/stata-treemap/main/installation/") replace
Expand Down Expand Up @@ -69,8 +69,7 @@ treemap numvar [if] [in], by(variables (min=1 max=3))
[ xsize(num) ysize(num) percent format(str) sformat(str) labcond(num) palette(it:str) colorby(var)
pad(list) labsize(list) linewidth(list) linecolor(list) fi(list)
addtitles novalues nolabels labsize(num) titlegap(num) labgap(str)
threshold(num) fade(num) labprop titleprop labscale(num) colorprop
title(str) subtitle(str) note(str) scheme(str) name(str) saving(str) ]
threshold(num) fade(num) labprop titleprop labscale(num) colorprop wrap(num) * ]
```

See the help file `help treemap` for details.
Expand All @@ -86,6 +85,34 @@ where `numvar` is a numeric variable, and `by()` is upto three string variables,



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

*or simple text*

```
Naqvi, A. (2024). Stata package "treemap" version 1.55. Release date 10 June 2024. https://github.com/asjadnaqvi/stata-treemap.
```


*or see [SSC citation](https://ideas.repec.org/c/boc/bocode/s459123.html) (updated once a new version is submitted)*




## Examples

Set up the data:
Expand Down Expand Up @@ -372,6 +399,10 @@ Please open an [issue](https://github.com/asjadnaqvi/stata-treemap/issues) to re

## Change log

**v1.55 (10 Jun 2024)**
- Added `wrap()` for label wrapping.
- Minor fixes.

**v1.54 (20 Apr 2024)**
- `colorby()` fixed. This option now requires a variable name that determines the color order (reported by Adam Okulicz-Kozaryn).
- Minor fixes.
Expand Down
4 changes: 2 additions & 2 deletions installation/stata.toc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
v 1.54
v 1.55
d 'TREEMAP': A Stata package for tree maps.
d
d Distribution-Date: 20240420
d Distribution-Date: 20240610
d
d Asjad Naqvi
d [email protected]
Expand Down
118 changes: 114 additions & 4 deletions installation/treemap.ado
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*! treemap v1.54 (20 Apr 2024)
*! treemap v1.55 (10 Jun 2024)
*! Asjad Naqvi ([email protected])

* v1.55 (10 Jun 2024): wrap() for label wraps.
* v1.54 (20 Apr 2024): colorby() fixed. Now requires a variable name for the color order.
* v1.53 (10 Apr 2024): Critical bug fix which was messing up the drawings if a third layer was defined.
* v1.52 (20 Jan 2024): If by() variables had empty rows, the program was giving an error. These are now dropped by default.
Expand All @@ -25,12 +26,11 @@ prog def treemap, sortpreserve

syntax varlist(numeric max=1) [if] [in], by(varlist min=1 max=3) ///
[ XSize(real 5) YSize(real 3) format(str) palette(string) ADDTitles NOVALues NOLABels ] ///
[ title(passthru) subtitle(passthru) note(passthru) scheme(passthru) name(passthru) saving(passthru) ] ///
[ pad(numlist max=3) labprop labscale(real 0.3333) labcond(real 0) colorprop titlegap(real 0.1) titleprop LINEWidth(string) LINEColor(string) LABSize(string) ] /// // v1.1 options. labscale is undocumented labprop scaling
[ fi(numlist max=3) ] /// // v1.2 options
[ LABGap(string) ] /// // v1.3 options
[ Share SFORmat(str) THRESHold(numlist max=1 >=0) fade(real 10) percent ] /// // v1.4, v1.5 options
[ colorby(varname) sharevar(varname) ]
[ colorby(varname) sharevar(varname) wrap(numlist >=0 max=1) * ]

marksample touse, strok

Expand Down Expand Up @@ -374,6 +374,42 @@ preserve
}


// wrap
if "`wrap'" != "" {

// layer 0
gen _length0 = length(_l0_lab0) if _l0_lab0!= ""
summ _length0, meanonly
local _wraprounds0 = floor(`r(max)' / `wrap')

forval i = 1 / `_wraprounds0' {
local wraptag = `wrap' * `i'
replace _l0_lab0 = substr(_l0_lab0, 1, `wraptag') + "`=char(10)'" + substr(_l0_lab0, `=`wraptag' + 1', .) if _length0 > `wraptag' & _length0!=.
}

// layer 1
gen _length1 = length(_l0_lab1) if _l0_lab1!= ""
summ _length1, meanonly
local _wraprounds1 = floor(`r(max)' / `wrap')

forval i = 1 / `_wraprounds0' {
local wraptag = `wrap' * `i'
replace _l0_lab1 = substr(_l0_lab1, 1, `wraptag') + "`=char(10)'" + substr(_l0_lab1, `=`wraptag' + 1', .) if _length1 > `wraptag' & _length1!=.
}

// layer 2
gen _length2 = length(_l0_lab2) if _l0_lab2!= ""
summ _length2, meanonly
local _wraprounds2 = floor(`r(max)' / `wrap')

forval i = 1 / `_wraprounds2' {
local wraptag = `wrap' * `i'
replace _l0_lab2 = substr(_l0_lab2, 1, `wraptag') + "`=char(10)'" + substr(_l0_lab2, `=`wraptag' + 1', .) if _length2 > `wraptag' & _length2!=.
}

drop _length*
}


**************
** layer1 **
Expand Down Expand Up @@ -434,6 +470,43 @@ preserve
replace _l1_`z'_lab0= "{it:" + _l1_`z'_lab1 + "}" if _l1_`z'_val >= `labcond'
}


// wrap
if "`wrap'" != "" {

// layer 0
gen _length0 = length(_l1_`z'_lab0) if _l1_`z'_lab0!= ""
summ _length0, meanonly
local _wraprounds0 = floor(`r(max)' / `wrap')

forval i = 1 / `_wraprounds0' {
local wraptag = `wrap' * `i'
replace _l1_`z'_lab0 = substr(_l1_`z'_lab0, 1, `wraptag') + "`=char(10)'" + substr(_l1_`z'_lab0, `=`wraptag' + 1', .) if _length0 > `wraptag' & _length0!=.
}

// layer 1
gen _length1 = length(_l1_`z'_lab1) if _l1_`z'_lab1!= ""
summ _length1, meanonly
local _wraprounds1 = floor(`r(max)' / `wrap')

forval i = 1 / `_wraprounds0' {
local wraptag = `wrap' * `i'
replace _l1_`z'_lab1 = substr(_l1_`z'_lab1, 1, `wraptag') + "`=char(10)'" + substr(_l1_`z'_lab1, `=`wraptag' + 1', .) if _length1 > `wraptag' & _length1!=.
}

// layer 2
gen _length2 = length(_l1_`z'_lab2) if _l1_`z'_lab2!= ""
summ _length2, meanonly
local _wraprounds2 = floor(`r(max)' / `wrap')

forval i = 1 / `_wraprounds2' {
local wraptag = `wrap' * `i'
replace _l1_`z'_lab2 = substr(_l1_`z'_lab2, 1, `wraptag') + "`=char(10)'" + substr(_l1_`z'_lab2, `=`wraptag' + 1', .) if _length2 > `wraptag' & _length2!=.
}

drop _length*
}

}

}
Expand Down Expand Up @@ -504,6 +577,43 @@ preserve
replace _l2_`z'_`y'_lab0 = "{it:" + _l2_`z'_`y'_lab1 + "}" in 1/`item2' if _l2_`z'_`y'_val >= `labcond'
}


// wrap
if "`wrap'" != "" {

// layer 0
gen _length0 = length(_l2_`z'_`y'_lab0) if _l2_`z'_`y'_lab0 != ""
summ _length0, meanonly
local _wraprounds0 = floor(`r(max)' / `wrap')

forval i = 1 / `_wraprounds0' {
local wraptag = `wrap' * `i'
replace _l2_`z'_`y'_lab0 = substr(_l2_`z'_`y'_lab0, 1, `wraptag') + "`=char(10)'" + substr(_l2_`z'_`y'_lab0, `=`wraptag' + 1', .) if _length0 > `wraptag' & _length0!=.
}

// layer 1
gen _length1 = length(_l2_`z'_`y'_lab1) if _l2_`z'_`y'_lab1 != ""
summ _length1, meanonly
local _wraprounds0 = floor(`r(max)' / `wrap')

forval i = 1 / `_wraprounds0' {
local wraptag = `wrap' * `i'
replace _l2_`z'_`y'_lab1 = substr(_l2_`z'_`y'_lab1, 1, `wraptag') + "`=char(10)'" + substr(_l2_`z'_`y'_lab1, `=`wraptag' + 1', .) if _length1 > `wraptag' & _length1!=.
}


// layer 2
gen _length2 = length(_l2_`z'_`y'_lab2) if _l2_`z'_`y'_lab2!= ""
summ _length2, meanonly
local _wraprounds2 = floor(`r(max)' / `wrap')

forval i = 1 / `_wraprounds2' {
local wraptag = `wrap' * `i'
replace _l2_`z'_`y'_lab2 = substr(_l2_`z'_`y'_lab2, 1, `wraptag') + "`=char(10)'" + substr(_l2_`z'_`y'_lab2, `=`wraptag' + 1', .) if _length2 > `wraptag' & _length2!=.
}

drop _length*
}

}
}
Expand Down Expand Up @@ -679,7 +789,7 @@ preserve
xscale(off) yscale(off) ///
xlabel(, nogrid) ylabel(, nogrid) ///
xsize(`xsize') ysize(`ysize') ///
`title' `subtitle' `note' `scheme' `name' `saving'
`options'

*/
restore
Expand Down
6 changes: 3 additions & 3 deletions installation/treemap.pkg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
v 1.54
v 1.55
d {bf:TREEMAP}: A Stata package for treemaps
d
d Requires: Stata version 15 or higher.
Expand All @@ -8,9 +8,9 @@ d KW: graphs
d KW: treemap
d KW: squarify
d
d Distribution-Date: 20240420
d Distribution-Date: 20240610
d
d This version: 20 Apr 2024
d This version: 10 Jun 2024
d First version: 08 Sep 2022
d License: MIT
d
Expand Down
33 changes: 27 additions & 6 deletions installation/treemap.sthlp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{smcl}
{* 20Apr2024}{...}
{* 10Jun2024}{...}
{hi:help treemap}{...}
{right:{browse "https://github.com/asjadnaqvi/stata-treemap":treemap v1.54 (GitHub)}}
{right:{browse "https://github.com/asjadnaqvi/stata-treemap":treemap v1.55 (GitHub)}}

{hline}

Expand All @@ -22,7 +22,7 @@ and on the Python's {browse "https://github.com/laserson/squarify":squarify} alg
{cmd:[} {cmdab:xs:ize}({it:num}) {cmdab:ys:ize}({it:num}) {cmd:format}({it:str}) {cmd:share} {cmd:sformat}({it:str}) {cmd:palette}(it:str) {cmd:colorby}({it:var})
{cmd:pad}({it:list}) {cmdab:labs:ize}({it:list}) {cmdab:linew:idth}({it:list}) {cmdab:linec:olor}({it:list}) {cmd:fi}({it:list}) {cmd:labcond}({it:num})
{cmdab:addt:itles} {cmdab:noval:ues} {cmdab:nolab:els} {cmdab:labs:ize}({it:num}) {cmd:titlegap}({it:num}) {cmdab:labg:ap}({it:str})
{cmdab:thresh:old}({it:num}) {cmd:fade}({it:num}) {cmd:labprop} {cmd:titleprop} {cmd:labscale}({it:num}) {cmd:colorprop}
{cmdab:thresh:old}({it:num}) {cmd:fade}({it:num}) {cmd:labprop} {cmd:titleprop} {cmd:labscale}({it:num}) {cmd:colorprop} {cmd:wrap}({it:num})
{cmd:title}({it:str}) {cmd:subtitle}({it:str}) {cmd:note}({it:str}) {cmd:scheme}({it:str}) {cmd:name}({it:str}) {cmd:saving}({it:str}) {cmd:]}


Expand Down Expand Up @@ -69,6 +69,8 @@ in combination with {opt percent} then the threshold will use the percentage val
{p2coldent : {opt pad(numlist max=3)}}The padding of the boxes, which can be defined as a list. The default values are {opt :pad(0.012 0.01 0.01)} for the three layers. A value of 0
implies no padding. If you change the {opt xsize} and {opt ysize} substantially, then you might also need to update the padding.{p_end}

{p2coldent : {opt wrap(num)}}Wrap the labels after a number of characters. A good starting point for very long labels is {opt wrap(50)}.{p_end}

{p2coldent : {opt labs:ize(string max=3)}}The size of the labels. The default values are {opt labs(1.6 1.6 1.6)}. If only one value is specified, it will passed on to all the layers.{p_end}

{p2coldent : {opt linew:idth(string max=3)}}The line width of the boxes. The default values are {opt linew(0.03 0.03 0.03)}. If only one value is specified, it will passed on to all the layers.{p_end}
Expand Down Expand Up @@ -128,8 +130,8 @@ Please submit bugs, errors, feature requests on {browse "https://github.com/asja

{title:Package details}

Version : {bf:treemap} v1.54
This release : 20 Apr 2024
Version : {bf:treemap} v1.55
This release : 10 Jun 2024
First release: 08 Sep 2022
Repository : {browse "https://github.com/asjadnaqvi/treemap":GitHub}
Keywords : Stata, graph, treemap, squarify
Expand All @@ -140,6 +142,23 @@ E-mail : [email protected]
Twitter : {browse "https://twitter.com/AsjadNaqvi":@AsjadNaqvi}



{title:Citation guidelines}

Suggested citation guidlines for this package:

Naqvi, A. (2024). Stata package "treemap" version 1.55. Release date 10 June 2024. https://github.com/asjadnaqvi/stata-treemap.

@software{treemap,
author = {Naqvi, Asjad},
title = {Stata package ``treemap''},
url = {https://github.com/asjadnaqvi/stata-treemap},
version = {1.55},
date = {2024-06-10}
}



{title:References}

{p 4 8 2}Bruls, M., Huizing, K., van Wijk Jarke J. (2000). {browse "https://link.springer.com/chapter/10.1007/978-3-7091-6783-0_4":Squarified Treemaps}. Data Visualization 2000, Eurographics.
Expand All @@ -157,4 +176,6 @@ Twitter : {browse "https://twitter.com/AsjadNaqvi":@AsjadNaqvi}

{psee}
{helpb arcplot}, {helpb alluvial}, {helpb bimap}, {helpb bumparea}, {helpb bumpline}, {helpb circlebar}, {helpb circlepack}, {helpb clipgeo}, {helpb delaunay}, {helpb joyplot},
{helpb marimekko}, {helpb sankey}, {helpb schemepack}, {helpb spider}, {helpb streamplot}, {helpb sunburst}, {helpb treecluster}, {helpb treemap}, {helpb waffle}
{helpb marimekko}, {helpb polarspike}, {helpb sankey}, {helpb schemepack}, {helpb spider}, {helpb streamplot}, {helpb sunburst}, {helpb treecluster}, {helpb treemap}, {helpb waffle}

or visit {browse "https://github.com/asjadnaqvi":GitHub} for detailed documentation and examples.

0 comments on commit a3c82e6

Please sign in to comment.