asjadnaqvi / stata-alluvial

A Stata package for alluvial plots
MIT License
5 stars 3 forks source link

Color control of categories at levels - add color controls #16

Open ericmelse opened 1 year ago

ericmelse commented 1 year ago

Dear Asjad, It is great to be able to use Ben Jann's palettes and colrspace to control colors, but, that implies (on first sight) their general use and much less their specific use for color coding categories on leveld. Myself, I am very 'picky' when it comes to the control of colors and rather want to select them individually for about anything. But, let me first follow your guidelines and run my example using:

use "MBO22Keuzedelen_Start_20230413.dta" , clear
gen c_keuzedl=1
replace c_keuzedl=2 if KEUZEDEELKEUZE==3
replace c_keuzedl=3 if KEUZEDEELKEUZE==2
replace c_keuzedl=4 if KEUZEDEELKEUZE==4
label define lbl_c_keuzedl 1 "Oriënteren" 2 "Samenwerken" 3 "Analyseren'" 4 "Reflecteren" , replace
label values c_keuzedl lbl_c_keuzedl
label var c_roc "College"
label var vrouw "Studenten"
label var c_keuzedl "Keuzedeel"
alluvial c_roc vrouw c_keuzedl , laba(90) labs(*1.4) showtot boxw(*20) shares vals(*1.2) valf(%12.2f) valgap(*5) palette(carto) name(roc, replace)

which results in: Alluvial_test_2_20230418 Never mind the cluttered labels at the levels and the super small level titels (we deal with that later).

Note that I have used palette(carto) and that by inspection of that palette, using: Palette_Carto_20230418 I analyse where which palette color was used by alluvial, using: Alluvial_test_2_20230418_Palette_Chk My first thought is 'how does this come about'? What logic decides to use which color for the individual categories at each level? Should your code apply some algorithm to 'cherry pick' colors from the palette, possibly people will appreciate that (no pun intended). But, I would like to be in control and be able to assign (set) selected colors of such palette to the levels. I can think of various ways of coding that but forgive me for being ignorant what would be the most concise but flexible way of coding. For example, could:

palettelevels(# "str")
The allocation of the colors of the palette(name) by their code to the categories of the levels used.
Default is palettelevels(auto) for automatic color allocation.
Note that when not all categories or not each level is allocated individually that then their default selected color applies (which might result in the multiple use of such colors).

work in your module? Like with my Example: palette(carto) levelcolors(1 "5 2 7" 2 "3 10 7" 3 "6 9 1 8")

Ideally, I also really would like to be able to control the colors using all Stata's parameters for colors, like:

* Functional only when palette("str") is not used:
levelcolors(1 "gs11 green sanb" 2 ""255 255 130%50" "255 130 255*1.1"" 3 blue%40 blue%60 blue%80 blue*1.2")

Well, I submit to you that I am a 'demanding' person.

Best, Eric

asjadnaqvi commented 1 year ago

This has been requested for several packages esp sankey. A potential solution is to add a colorby(variable) option. This allows users to define their own order, highlight certain regions, and keep full control of the colors.

asjadnaqvi commented 1 year ago

Also the default color order is alphabetical. A numerical or a level sort has been implented in sankey but has not been ported over to alluvial.

Merge with #12