Announcement

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

  • bar graph for the following data with different bar colors

    input str20 country pcexp
    Greece 371
    Portugal 474
    Spain 646
    Italy 784
    Sweden 1245
    Denmark 1456
    Canada 1689
    USA 2634
    end

    The above is my data. I would like to draw a bar graph for each country with pcexp( per-capita expenditure) as count with the number on the top of each bar. Stata should treat pcexp value as for example, frequency. And separate fill colors for each bar.

    Any idea Nice people here?

  • #2
    For a more professional look, don't do this in a bar chart. As Naomi Robbins says somewhere would you give a different colour to each word in a sentence?

    For a professional look, consider highlighting just one country because it is of special interest to your story.

    If you are determined to do it any way, it is easy to get different colours by supplying different variables or by telling Stata to treat your data as if they were several different variables. But it seems harder to do it in ways that (1) don't provoke an unnecessary legend (2) allow easy ordering by a helpful criterion (not something dopey like alphabetical name order).

    This is one solution; there will be others.


    Code:
    clear 
    input str20 country pcexp
    Greece 371
    Portugal 474
    Spain 646
    Italy 784
    Sweden 1245
    Denmark 1456
    Canada 1689
    USA 2634
    end
    
    * Stata Journal https://www.stata-journal.com/article.html?article=st0654 
    myaxis order=country, sort(mean pcexp) descending 
    
    separate pcexp, by(country) veryshortlabel 
    
    set scheme s1color 
    graph hbar (asis) pcexp?, nofill over(order) asyvars legend(off) ysc(alt titlegap(*5)) ytitle(explain pcexp here)
    Click image for larger version

Name:	rainbow.png
Views:	1
Size:	24.0 KB
ID:	1638139

    Comment


    • #3
      I understood your point. Thank you very much sir.
      Much appreciated.

      Comment

      Working...
      X