Announcement

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

  • Graph bar, change the bar color

    Hi Everyone,

    I would like to ask an unusual question. I need to change the color to Stata bars using graph bar, but in a different ways that what all other posts have asks. What I need is changing the colors of selected bars, despite the over options I use. Here's my command:

    graph bar frac_, over(v1, sort(n) label(angle(45) labsize(small))) over(ind, sort(v2)) nofill ///
    bar(1, fcolor(ebblue%70) fintensity(inten100) lcolor(ebblue%70) lwidth(vthin)) bar(2, fcolor(ebblue%70) fintensity(inten100) lcolor(ebblue%70) lwidth(vthin))///
    plotregion(lcolor(white)) ytitle("Percentage", size(3)) blabel(bar, format(%9.1f) color(black)) graphregion(color(white))


    The option asyvars doesn't work because it changes all the labels and remove the order I would like to use.

    Thanks a lot,

    Josh

  • #2
    Data example, please

    Comment


    • #3
      Thanks Hemanshu, here it is:

      ID var1 var2 sample1 A 1 sample2 B 1 sample3 C 1 sample4 C 1 sample5 A 2 sample6 B 3 sample7 C 2 sample8 A 4 sample9 A 4 sample10 A 5 With the following code, I generated the attached graph.
      graph bar (count), over(var1) over(var2)
      Click image for larger version

Name:	36N7g.png
Views:	2
Size:	88.5 KB
ID:	1771944
      What I'm trying to get here is to color the groups 1, 2, 3, 4 and 5 in different colors, but the bars must be in the same color... e.g. A,B,C from group 1 in blue, A,B,C from group 2 in green, A,B,C from group 3 in yellow, A,B,C from group 4 in brown and A,B,C from group 5 in black...
      Attached Files
      Hi Everyone, I would like to ask an unusual question. I need to change the color to Stata bars using graph bar, but in a different ways that what all other

      Comment


      • #4
        Please see

        https://www.statalist.org/forums/help#realnames (?)

        https://www.statalist.org/forums/help#version

        https://www.statalist.org/forums/help#stata 12.2

        This may help otherwise

        Code:
        clear 
        input str9 ID str1 var1 var2 
        sample1 A 1 
        sample2 B 1 
        sample3 C 1 
        sample4 C 1 
        sample5 A 2 
        sample6 B 3 
        sample7 C 2 
        sample8 A 4 
        sample9 A 4 
        sample10 A 5
        end 
        
        preserve 
        
        contract var1 var2 , zero 
        
        separate _freq, by(var2)
        
        graph bar _freq?, over(var1) over(var2) yla(0/2) nofill ///
        bar(1, color(blue)) bar(2, color(green)) bar(3, color(yellow))  bar(4, color(brown))  bar(5, color(black)) ///
        legend(off) ytitle(Frequency)
        
        restore
        Click image for larger version

Name:	joshua.png
Views:	1
Size:	28.9 KB
ID:	1771947

        Comment

        Working...
        X