I am looking for the way to colorize the slices in a pie chart in a specific way. Consider the following example:
Code:
clear all input v 101 101 101 102 101 102 103 104 103 102 103 end tabulate v graph pie , over(v) plabel(_all name, color(yellow)) legend(rows(1)) /// pie(1, color(64 0 0)) pie(2, color(128 0 0)) /// pie(3, color(192 0 0)) pie(4, color(255 0 0)) /// name(g1) title("All") replace v=101 if v==102 tabulate v // this is NOT the result that I want: graph pie , over(v) plabel(_all name, color(yellow)) legend(rows(1)) /// pie(1, color(64 0 0)) pie(2, color(128 0 0)) /// pie(3, color(192 0 0)) pie(4, color(255 0 0)) /// name(g2) title("Bad") // this is the result that I want: graph pie , over(v) plabel(_all name, color(yellow)) legend(rows(1)) /// pie(1, color(64 0 0)) /// pie(2, color(192 0 0)) pie(3, color(255 0 0)) /// name(g3) title("Good") graph combine g1 g2 g3, rows(1) scale(0.5)
I want the specific colors to apply by the type of item (104 to be colored bright-red), while its actual index depends whether the other items are present in the data.
Ideally I would like to find a magic function sectorNumberByValue() with an argument of the domain (numeric or string) of over(), returning the sector number from the value to which that sector corresponds. Then I could do:
Code:
graph pie , over(v) plabel(_all name, color(yellow)) legend(rows(1)) /// pie(sectorNumberByValue(101), color(64 0 0)) pie(sectorNumberByValue(102), color(128 0 0)) /// pie(sectorNumberByValue(103), color(192 0 0)) pie(sectorNumberByValue(104), color(255 0 0)) /// name(g2) title("Bad")
Is there a simpler way?
Thank you, Sergiy Radyakin
Comment