Hi!
I'm having a problem with how my colors are displayed in spmap. Here's the code (I'm not copying and pasting all the code needed to create the map, because everything else works perfectly—it's just when I change the colors that I run into this issue) :
gen ratio = (amount_share/circ_share)
centile ratio, centile( 20 40 60 80 100)
forvalues i = 1/4 {
local c`i' = round(`r(c_`i')',0.10)
}
local max = ceil(`r(c_5)')
spmap ratio if period == 0 using "$Maps/india_statecoord", id(id) clmethod(custom) clbreaks(0 `c1' `c2' `c3' `c4' `max') fcolor(Blues) ndfcolor(gray) title("Before 2015") legend(size(medium)) saving(graph0, replace)
spmap ratio if period == 1 using "$Maps/india_statecoord", id(id) clmethod(custom) clbreaks(0 `c1' `c2' `c3' `c4' `max') fcolor(Blues) ndfcolor(gray) title("After 2015") legend(size(medium)) saving(graph1, replace)
graph combine graph0.gph graph1.gph, col(2) graphregion(color(white))
graph export "$Figures\ratio_state_map_daily.pdf", as(pdf) replace
graph export "$Figures\ratio_state_map_daily.pdf", as(pdf) replace
erase graph0.gph
erase graph1.gph
gen sur = 1
replace sur=2 if ratio>=0.5 & ratio<0.9
replace sur=3 if ratio>= 0.9 & ratio<=1.1
replace sur=4 if ratio>1.1 & ratio<2
replace sur=5 if ratio>=2
// Vérification rapide (à faire dans le log)
// tab sur if period == 0
// tab sur if period == 1
spmap sur if period == 1 using "$Maps/india_statecoord", ///
id(id) ///
clmethod(custom) ///
clbreaks(0 1.5 2.5 3.5 4.5) ///
fcolor(blue*0.7 blue*1 green*0.3 red*0.3 red*0.7) ///
title("After 2015") ///
legend(size(large) ring(1) position(6) ///
order(1 2 3 4 5) ///
label(1 "[0-0.5[") ///
label(2 "[0.5-0.9[") ///
label(3 "[0.9-1.1]") ///
label(4 "]1.1-2[") ///
label(5 ">2") ///
region(fcolor(white) lcolor(none))) ///
ndfcolor(white) ///
saving(graph1, replace)
The problem is that all my colors are off. Specifically, Category 1 is shown as white in the legend instead of blue*0.7. Therefore, the last category is supposed to be dark red, not light red (I've listed the colors in the order of my “sur” variable). Aside from the fact that the colors in my legend don’t match my code, the legend doesn’t correspond to what’s shown on the map. For example, Tamil has a ratio of 4. According to my code, it should therefore be light red. Admittedly, it is light red on the map, but the legend states that light red represents states with a ratio > 2, whereas Tamil Nadu has a ratio between 1.1 and 2 (1.5), so the legend is incorrect, but the color is correct. For Andhra Pradesh, sur=1. According to my code, it should be light blue. That’s the case (blue*0.7), but the legend indicates that for Andhra Pradesh, sur=2...

Thanks in advance to the Stata community !
I'm having a problem with how my colors are displayed in spmap. Here's the code (I'm not copying and pasting all the code needed to create the map, because everything else works perfectly—it's just when I change the colors that I run into this issue) :
gen ratio = (amount_share/circ_share)
centile ratio, centile( 20 40 60 80 100)
forvalues i = 1/4 {
local c`i' = round(`r(c_`i')',0.10)
}
local max = ceil(`r(c_5)')
spmap ratio if period == 0 using "$Maps/india_statecoord", id(id) clmethod(custom) clbreaks(0 `c1' `c2' `c3' `c4' `max') fcolor(Blues) ndfcolor(gray) title("Before 2015") legend(size(medium)) saving(graph0, replace)
spmap ratio if period == 1 using "$Maps/india_statecoord", id(id) clmethod(custom) clbreaks(0 `c1' `c2' `c3' `c4' `max') fcolor(Blues) ndfcolor(gray) title("After 2015") legend(size(medium)) saving(graph1, replace)
graph combine graph0.gph graph1.gph, col(2) graphregion(color(white))
graph export "$Figures\ratio_state_map_daily.pdf", as(pdf) replace
graph export "$Figures\ratio_state_map_daily.pdf", as(pdf) replace
erase graph0.gph
erase graph1.gph
gen sur = 1
replace sur=2 if ratio>=0.5 & ratio<0.9
replace sur=3 if ratio>= 0.9 & ratio<=1.1
replace sur=4 if ratio>1.1 & ratio<2
replace sur=5 if ratio>=2
// Vérification rapide (à faire dans le log)
// tab sur if period == 0
// tab sur if period == 1
spmap sur if period == 1 using "$Maps/india_statecoord", ///
id(id) ///
clmethod(custom) ///
clbreaks(0 1.5 2.5 3.5 4.5) ///
fcolor(blue*0.7 blue*1 green*0.3 red*0.3 red*0.7) ///
title("After 2015") ///
legend(size(large) ring(1) position(6) ///
order(1 2 3 4 5) ///
label(1 "[0-0.5[") ///
label(2 "[0.5-0.9[") ///
label(3 "[0.9-1.1]") ///
label(4 "]1.1-2[") ///
label(5 ">2") ///
region(fcolor(white) lcolor(none))) ///
ndfcolor(white) ///
saving(graph1, replace)
The problem is that all my colors are off. Specifically, Category 1 is shown as white in the legend instead of blue*0.7. Therefore, the last category is supposed to be dark red, not light red (I've listed the colors in the order of my “sur” variable). Aside from the fact that the colors in my legend don’t match my code, the legend doesn’t correspond to what’s shown on the map. For example, Tamil has a ratio of 4. According to my code, it should therefore be light red. Admittedly, it is light red on the map, but the legend states that light red represents states with a ratio > 2, whereas Tamil Nadu has a ratio between 1.1 and 2 (1.5), so the legend is incorrect, but the color is correct. For Andhra Pradesh, sur=1. According to my code, it should be light blue. That’s the case (blue*0.7), but the legend indicates that for Andhra Pradesh, sur=2...
Thanks in advance to the Stata community !

Comment