Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Different colors for single text in graph legend

    I have a stacked graph with the government and private spending. I made some of the bars have different colors in other to highlight some of the categories in the x-axis that I am the most interested in. However, they still inform the same thing (government and private spending). Would it be possible to have different colors associated to a single text in the legend? More specifically, I would like to have the dark blue, dark red and black colors (bottom bars) associated with the legend "Government" and the light blue, light red and grey colors (top bars) associated with the legend "Private Sector + DAH".

    So far, my code is as follow:
    Code:
    separate percap_gov, by(d_graf)
    separate percap_pri, by(d_graf)
    
    graph bar percap_gov1 percap_gov2 percap_gov3 percap_gov4 percap_gov5 /// 
    percap_gov6 percap_gov7 percap_gov8 percap_gov9 percap_pri1 percap_pri2 /// 
    percap_pri3 percap_pri4 percap_pri5 percap_pri6 percap_pri7 percap_pri8 percap_pri9 ///
    if year==2015 & selection==1, stack ///
    over(location, label(angle(90) labsize(small)) sort(percap_total) descending) ///
    ytitle("") yscale(off) nofill ///
    ysize(9) xsize(18) graphregion(color(white)) ylab(, nogrid) ///
    legend(label(1 "Government") label(2 "Government") label(3 "Government") label(4 "Government") ///
    label(5 "Government") label(6 "Government") label(7 "Government") label(8 "Government") ///
    label(9 "Government") label(10 "Private Sector + DAH") label(11 "Private Sector + DAH") ///
    label(12 "Private Sector + DAH") label(13 "Private Sector + DAH") label(14 "Private Sector + DAH") ///
    label(15 "Private Sector + DAH") label(16 "Private Sector + DAH") label(17 "Private Sector + DAH") ///
    label(18 "Private Sector + DAH") ///
    pos(1) col(1) ring(0) size(small) region(c(none))) ///
    bar(1, bcolor(blue*1.3)) bar(2, bcolor(red*1.2)) bar(3, bcolor(black)) bar(4, bcolor(black)) bar(5, bcolor(black)) ///
    bar(6, bcolor(black)) bar(7, bcolor(black)) bar(8, bcolor(black)) bar(9, bcolor(black)) ///
    bar(10, bcolor(blue*0.1)) bar(11, bcolor(red*0.2)) bar(12, bcolor(black*0.2)) bar(13, bcolor(black*0.2)) ///
    bar(14, bcolor(black*0.2)) bar(15, bcolor(black*0.2)) bar(16, bcolor(black*0.2)) bar(17, bcolor(black*0.2)) ///
    bar(18, bcolor(black*0.2))
    Click image for larger version

Name:	graf_percap_stack2.png
Views:	1
Size:	52.0 KB
ID:	1446568
Working...
X