Announcement

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

  • Bar Graph - Highlight Specific Bar

    Click image for larger version

Name:	dataex.png
Views:	1
Size:	16.9 KB
ID:	1500350

    I have generated the above graph using the following code :
    Code:
    graph bar, over(region) blabel(bar) ytitle(Percent) by(, title("Market Share by Region") subtitle("Top 100")) by(year)
    How can I highlight EU-27 using different color, say, green?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double year str5 region
    2010 "US"   
    2010 "US"   
    2010 "US"   
    2010 "EU-27"
    2010 "Other"
    2010 "US"   
    2010 "Other"
    2010 "US"   
    2010 "US"   
    2010 "US"   
    2010 "US"   
    2010 "US"   
    2010 "Other"
    2010 "US"   
    2010 "US"   
    2010 "Other"
    2010 "US"   
    2010 "US"   
    2010 "US"   
    2010 "US"   
    2010 "UK"   
    2010 "Other"
    2010 "US"   
    2010 "UK"   
    2010 "UK"   
    2010 "US"   
    2010 "Other"
    2010 "US"   
    2010 "Other"
    2010 "Other"
    2010 "Other"
    2010 "EU-27"
    2010 "US"   
    2010 "Other"
    2010 "US"   
    2010 "US"   
    2010 "EU-27"
    2010 "US"   
    2010 "US"   
    2010 "Other"
    2010 "EU-27"
    2010 "UK"   
    2010 "Other"
    2010 "Other"
    2010 "US"   
    2010 "US"   
    2010 "US"   
    2010 "Other"
    2010 "US"   
    2010 "UK"   
    2010 "Other"
    2010 "Other"
    2010 "US"   
    2010 "EU-27"
    2010 "EU-27"
    2010 "Other"
    2010 "EU-27"
    2010 "EU-27"
    2010 "Other"
    2010 "UK"   
    2010 "Other"
    2010 "US"   
    2010 "EU-27"
    2010 "Other"
    2010 "Other"
    2010 "US"   
    2010 "Other"
    2010 "US"   
    2010 "EU-27"
    2010 "US"   
    2010 "US"   
    2010 "EU-27"
    2010 "EU-27"
    2010 "UK"   
    2010 "Other"
    2010 "EU-27"
    2010 "Other"
    2010 "EU-27"
    2010 "Other"
    2010 "EU-27"
    2010 "Other"
    2010 "EU-27"
    2010 "EU-27"
    2010 "US"   
    2010 "Other"
    2010 "EU-27"
    2010 "EU-27"
    2010 "Other"
    2010 "Other"
    2010 "US"   
    2010 "UK"   
    2010 "UK"   
    2010 "UK"   
    2010 "UK"   
    2010 "Other"
    2010 "Other"
    2010 "UK"   
    2010 "UK"   
    2010 "EU-27"
    2010 "Other"
    end
    format %ty year

  • #2
    Don't I recall you asking this exact question before?

    Code:
    graph bar, over(region) blabel(bar) ytitle(Percent) by(, title("Market Share by Region") ///
    subtitle("Top 100") legend(off) note("")) by(year) asyvars  bargap(5) bar(1, color(green)) ///
    bar(2, color(blue)) bar(3, color(blue)) bar(4, color(blue)) showyvars
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	26.0 KB
ID:	1500357

    Comment


    • #3
      Andrew Musau Thanks a lot for the code! I asked similar yet different question before. Here it is https://www.statalist.org/forums/for...iple-variables.

      Note for future use : the following code (based on the above code) produces sorted bar graph!
      Code:
      graph bar, over(region, sort(1)) blabel(bar) ytitle(Percent) by(, title("Market Share by Region") ///
      subtitle("Top 100") legend(off) note("")) by(year) asyvars  bargap(5) bar(1, color(green)) ///
      bar(2, color(blue)) bar(3, color(blue)) bar(4, color(blue)) showyvars

      Comment

      Working...
      X