Closed Monefield closed 1 year ago
This is an issue related to colorpalette
, not geoplot
. The problem is that colorpalette
does not know that this is a qualitative palette. Things work fine of you declare the palette as qualitative. That is, define the palette as:
program colorpalette_colors_test
c_local P #FF0000, /// 1 - Red
#FF8000, /// 2 - Orange
#FFFF00, /// 3 - Yellow
#00FF00, /// 4 - Green
#00FFFF, /// 5 - Cyan
#0000FF // 6 - Blue
c_local class qualitative
end
Alternatively, you could leave the palette definition as is and then type
geoplot (area regions pop98_cat3, discrete color(colors_test, class(qualitative) reverse))
or
geoplot (area regions pop98_cat3, discrete color(colors_test, select(1/3) reverse))
That I didn't know! Very clever and nice with the alternative solutions! Thank you :)
In my work I have to use specific colors in a specific order, so I have to use colorpalettes. I would like to use the colors in the order they are placed in the colorpalette (meaning that I always use the first X colors in the palette), but the reverse color-option seems to work differently than I would think when using colorpalettes. I have used your Italy-data for this small example:
label def pop98_cat3_lab 1 "Type 1" 2 "Type 2" 3 "Type 3", modify label val pop98_cat3 pop98_cat3_lab
When I don't use a colorpalette the reverse color-option works like I would think it did (uses the same colors, but reverses their order): No reverse color-option - Right colors (1 2 3), wrong order (1 2 3) geoplot (area regions pop98_cat3, discrete) /// , legend(reverse)
Reverse color-option - Right colors (1 2 3), right order (3 2 1) geoplot (area regions pop98_cat3, discrete color(, reverse)) /// , legend(reverse)
Using colorpalettes combined with the reverse color-option reverses both the order, but also the colors:
Colorpalette program colorpalette_colors_test c_local P #FF0000, /// 1 - Red
FF8000, /// 2 - Orange
end colorpalette colors_test
If I don't use the reverse color-option I get the right colors, but in the wrong order Right colors (1 2 3), wrong order (1 2 3): geoplot (area regions pop98_cat3, discrete color(colors_test)) /// , legend(reverse)
If I use the reverse color-option it reverses the palette as well Wrong colors (4 5 6), wrong order (6 5 4): geoplot (area regions pop98_cat3, discrete color(colors_test, reverse)) /// , legend(reverse)
I found a possible workaround where I use only the appropriate subselection of the colorpalette
Right colors (1 2 3), right order (3 2 1): colorpalette colors_test, select(1 2 3) nograph local colors_subselect `r(p)'
geoplot (area regions pop98_cat3, discrete color("`colors_subselect'", reverse)) /// , legend(reverse)
Since I've already found a workaround this is just wishfull thinking on my part, but it would be nice, that those two extra lines of code wasn't necessary :)