asjadnaqvi/stata-treemap

add option to color by category

Closed this issue · 4 comments

the following example shows that the categories of field are changing their colors when a different period is chosen. But I like to show that the same category of field has the same color throughout my project (especially, within a presentation...)

`clear
input double impact_p byte(field period)
3410.16666666667 3 1
4588.83333333333 3 7
5502.33333333333 3 12
365.166666666667 4 1
543 4 7
628.833333333333 4 12
160.5 5 1
136.333333333333 5 7
172.5 5 12
875.166666666667 6 1
1019.33333333333 6 7
1114.33333333333 6 12
147 7 1
374.5 7 7
524 7 12
end
label values field l_field_kurz
label def l_field_kurz 3 "BHS", modify
label def l_field_kurz 4 "LES", modify
label def l_field_kurz 5 "MCS", modify
label def l_field_kurz 6 "PSE", modify
label def l_field_kurz 7 "SSH", modify
label values period l_period
label def l_period 1 "2006–2009", modify
label def l_period 7 "2012–2015", modify
label def l_period 12 "2017–2020", modify
label var impact_p "Anzahl Publikationen"
label var field "Fächergruppe"
label var period "Auswertungszeitraum"

**# Treemap first period
treemap impact_p if period == 1, by(field) name(treemap_period1, replace)

**# Treemap last period
treemap impact_p if period == 12, by(field) name(treemap_period12, replace)`

what do you expect as name in the colorby-option?
adding colorby(field) in both treemap commands does not yield the expected result expected. At least SSH and MCS switch colors.
Attention: fields' numeric range is from 3 to 7.

colorby(field) is not a valid option. You need to specify colorby(name).

this works. Oh I was puzzled by the "name" option and thought it had to be specified. Wouldn't it be enough to call the option colorby - or do you think the option can be extented like you do with level/layer in the other programs?

That's the idea. To expand this later to allow other colorby() options. But I agree that currently it just seems reduendant.