Announcement

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

  • Labeling categorical axis using graph bar

    Hello

    I'm sure I'm missing something obvious in the manual, but I can't seem to properly label the axis of my bar graph.

    I'm drawing the following graph:

    Code:
    graph bar r_method*, ascat
    Where r_method* is several variables called r_method1, r_method2, r_method3, ..., etc

    How do I label the axis of the graph so it uses the variable labels (eg, variable label of r_method1) instead of it saying "mean of r_method1", etc?

    Very grateful for any advice!

    Click image for larger version

Name:	r_method.PNG
Views:	1
Size:	33.4 KB
ID:	1741092

  • #2
    graph bar's default of showing means is often fine; its default of telling you that it is showing means not so fine (for me).

    There are no doubt several ways to do this.I could easily be missing something too, but some involve different data layouts.

    Here's one slightly odd method. It makes an extra point that if a bare variable name r_method1 would be better, an informative variable label would be even better.

    Code:
    clear 
    set obs 100 
    set seed 2803 
    
    tokenize "frog toad newt"  
    
    forval j = 1/3 { 
        gen r_method`j' = runiform() > (`j' * 0.25) 
        label var r_method`j' "``j''"
    }
    
    * start here with 5 not 3 
    
    forval j = 1/3 { 
        egen mean`j' = mean(r_method`j')
        _crcslbl mean`j' r_method`j'
    } 
    
    graph bar (asis) mean* in 1 , ascat ytitle(means)

    Comment


    • #3
      Thank you, Nick - that works perfectly!

      Comment

      Working...
      X