Announcement

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

  • Highlighting a Bar in Bar Chart while using ascategory

    Hi!

    Here is my graph. I want to highlight a specific bar, lets say Headroom with in Domestic. How do I do that?
    Code:
    sysuse auto, clear
    graph hbar rep78 headroom gear_ratio, over(foreign) ascategory blabel(bar, size(small) format(%4.2f)) ///
    yvaroptions(label(labsize(small)) relabel(1 "Rep 78" 2 "Headroom" 3 "Gear Ratio"))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	48.2 KB
ID:	1552393


    The solution of this post did not work:
    https://www.statalist.org/forums/for...ighlighted-bar

    (PS: The only reason I am using "ascategory" because I want the variable names to be displayed. Without using as category, The variable names goes to legend and no way to put the variable names in the axis).

  • #2
    https://www.statalist.org/forums/help#stata

    12.1 What to say about your commands and your problem

    Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!

    If you are using community-contributed (also known as user-written) commands, explain that and say where they came from: the Stata Journal, SSC, or other archives. This helps (often crucially) in explaining your precise problem, and it alerts readers to commands that may be interesting or useful to them.

    Here are some examples:
    I am using xtreg in Stata 15.1.
    I am using estout from SSC in Stata 15.1.
    Never say just that something "doesn't work" or "didn't work", but explain precisely in what sense you didn't get what you wanted.


    Comment


    • #3
      (PS: The only reason I am using "ascategory" because I want the variable names to be displayed. Without using as category, The variable names goes to legend and no way to put the variable names in the axis).
      I disagree and say, yes way.


      Code:
      sysuse auto, clear
      foreach var in rep78 headroom gear_ratio{
         separate `var', by(foreign)
      }
      
      graph hbar rep780 headroom0 gear_ratio0 rep781 headroom1 gear_ratio1, over(foreign)  ///
      asyvars showyvars leg(off) bargap(29) nofill blabel(bar, size(small) format(%4.2f)) ///
      yvaroptions(label(labsize(small)) relabel(1 "Rep 78" 2 "Headroom" 3 "Gear Ratio" ///
      4 "Rep 78" 5 "Headroom" 6 "Gear Ratio" )) bar(1, color(navy)) bar(2, color(red))  ///
      bar(3, color(navy))  bar(4, color(navy))  bar(5, color(navy))  bar(6, color(navy))


      Click image for larger version

Name:	Graph.png
Views:	1
Size:	31.5 KB
ID:	1552402

      Comment


      • #4
        Originally posted by Andrew Musau View Post

        I disagree and say, yes way.


        Code:
        sysuse auto, clear
        foreach var in rep78 headroom gear_ratio{
        separate `var', by(foreign)
        }
        
        graph hbar rep780 headroom0 gear_ratio0 rep781 headroom1 gear_ratio1, over(foreign) ///
        asyvars showyvars leg(off) bargap(29) nofill blabel(bar, size(small) format(%4.2f)) ///
        yvaroptions(label(labsize(small)) relabel(1 "Rep 78" 2 "Headroom" 3 "Gear Ratio" ///
        4 "Rep 78" 5 "Headroom" 6 "Gear Ratio" )) bar(1, color(navy)) bar(2, color(red)) ///
        bar(3, color(navy)) bar(4, color(navy)) bar(5, color(navy)) bar(6, color(navy))


        [ATTACH=CONFIG]n1552402[/ATTACH]
        Thanks!

        Comment

        Working...
        X