Announcement

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

  • Graph bar colors by group

    Hi everybody,

    I have a simple question about bar graphs in Stata but I don't seem to find a solution.
    My current code:
    Code:
    graph bar gov_resp if year==1992, over(cntry, label(angle(45))) over(east) nofill
    produces the following graph:
    Click image for larger version

Name:	frage.png
Views:	1
Size:	35.2 KB
ID:	1505125



    I want everything to remain the same except for all the bars from West to be red, and all the bars from East to be blue. How can I do that?

    Many thanks in advance!

  • #2
    No data example here (FAQ Advice #12) but the following should help:


    Code:
    sysuse auto, clear
    separate mpg, by(foreign) veryshortlabel
    graph bar (mean) mpg0 mpg1, over(rep78) over(foreign) nofill bar(1, bcolor(red)) bar(2, bcolor(blue)) ///
    legend(off) ytitle(Mean miles per gallon)
    https://www.stata-journal.com/articl...article=gr0023

    https://www.stata-journal.com/articl...article=gr0049

    Horizontal bars would be more readable, avoiding the giraffe graphs of names at 45 degrees.

    Comment


    • #3
      Compare:
      Code:
      sysuse nlsw88, clear
      graph bar (mean) wage, over(smsa) over(married)
      separate wage, by(married)
      graph bar (mean) wage0 wage1, over(smsa) over(married) ///
       name(gr1,replace) bar(1, color(red)) bar(2, color(blue))
      See also,


      SJ-11-3 gr0049 . . . . . . . . . . Stata tip 102: Highlighting specific bars
      . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
      Q3/11 SJ 11(3):474--477
      tip on highlighting a subset of observations in a bar or
      dot chart

      https://www.stata-journal.com/sjpdf....iclenum=gr0049

      Comment


      • #4
        Great, thanks a lot, Nick, it helped!

        Comment

        Working...
        X