[R] Logrithmic histogram?

(Ted Harding) Ted.Harding at wlandres.net
Mon Jan 23 10:08:06 CET 2012


On 23-Jan-2012 Kevin Burton wrote:
> I have some data where the frequency is heavily weighted
> on the lower end. So I have lots of low values with very
> few higher values. I would like to find breakpoints that
> cover the data with as much detail as possible. I find
> that if I use hist() to automatically find the breaks for
> me it finds breaks that are too coarse for the low values.
> I have tried the other algorithms (like 'Scott' and 'FD')
> but I have been unable to get it to work for me. I think
> I need breaks based on the inverse logarithm of the frequency
> so that the low values which have a high frequency are more
> or less evenly distributed about like the lower frequency
> high values. Is there a function to find the breaks like this?
> 
> Thank you.
> Kevin

Kevin, you could try something along the following lines.
You may or may not like the look of the outcome, depending
on your data (and on your purposes in creating the histogram).

  X <- rlnorm(250)
  hist(X) ## Looks like what you describe

  H <- hist(log(X),breaks=20)  ## Use hist() to find the
                               ## logarithmic breaks. "breaks=20"
                               ## is optional!
  hist(X,breaks=exp(H$breaks)) ## So how does that look to you?

If that works satisfactorily, it is easy to encapsulate it in
a function.

Ted.




-------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at wlandres.net>
Date: 23-Jan-2012  Time: 09:08:02
This message was sent by XFMail



More information about the R-help mailing list