Announcement

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

  • Alternate colors on bar chart

    Hi,

    I am currently using the following code to generate the bar chart attached:

    graph hbar (count) count if sum > 5, over(college_name, label(angle(horizontal) labsize(tiny))) ///
    ylabel(0(100)3200) ///
    yscale(off) ///
    blabel(bar, size(tiny)) ///
    title("Teacher Credentialing Programs") ///
    subtitle("N = 10,620 Unique Applicants") ///
    note(N = 68 programs with > 5 applicants. $datetag)

    I would like to alternate the bar colors: Bar 1 blue, bar 2 yellow, bar 3 blue, bar 4 yellow, etc.
    Any suggestions on how to go about doing this would be greatly appreciated. Thank you!
    ​​​​​​​
    Attached Files

  • #2
    You need to specify the option asyvars so that Stata can recognize that each bar is unique. To recreate a similar graph, additional options are also necessary. Here I just include what you need to add


    Code:
     over(college_name, gap(30) label(angle(horizontal) labsize(tiny))) asyvars showyvars leg(off)
    This will automatically specify colors. To assign your own, further add

    Code:
    bar(1, bcolor(red)) bar(2, bcolor(blue))...

    Comment


    • #3
      This works. Thank you, Andrew!!

      Comment

      Working...
      X