Announcement

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

  • barchart: how to put the frequency axis on a log scale

    Dear all:

    I have a categorical variable with vastly unequal frequencies. I would like to display the frequencies on a log scale. I cannot seem to get the right syntax, though. Here is a simple example:

    clear
    input x freq
    0 3
    1 50
    2 500
    end;
    expand freq

    graph hbar (count) , over(x) // this works, not on a log scale
    graph hbar (count) , over(x) yscale(log) // does not work, weird graphical result

    Does anybody have a suggestion?

    Thanks,

    matthias

  • #2
    Stata wants to starts the bars at zero and is telling you that its desire to do that is not compatible with your desire to use a log scale.

    Although my sympathies here are with Stata, this perhaps is closer to what you want:

    Code:
    clear
    input x freq
    0 3
    1 50
    2 500
    end
    
    gen log_freq = log(freq)
    * ssc inst mylabels 
    mylabels 1 2 5 10 20 50 100 200 500, myscale(log(@)) local(yla)
    graph hbar (asis) log_freq, over(x) yla(`yla', ang(h))
    Whatever the base used, log(1) is evidently zero and bars can start at zero with such a scale.

    Comment


    • #3
      Not the question, but a square root scale is an alternative. Such a graph is often called a rootogram.

      Code:
      clear
      input x freq
      0 3
      1 50
      2 500
      end
      
      * ssc inst mylabels 
      mylabels 0 1 5 10 50 100 500, myscale(sqrt(@)) local(yla)
      set scheme s1color 
      spikeplot x [w=freq], base(0) root recast(bar) yla(`yla', ang(h)) xla(0/2) ytitle(Frequency (square root scale)) barw(0.9) bfcolor(none) 
      Click image for larger version

Name:	rootogram3.png
Views:	1
Size:	17.7 KB
ID:	1622339

      Comment

      Working...
      X