[R] log y 'axis' of histogram

Derek M Jones derek at knosof.co.uk
Mon Aug 30 14:50:01 CEST 2010


Hadley,

> It's not just that counts might be zero, but also that the base of
> each bar starts at zero. I really don't see how logging the y/axis of
> a histogram makes sense.

I have counts ranging over 4-6 orders of magnitude with peaks
occurring at various 'magic' values.  Using a log scale for the
y-axis enables the smaller peaks, which would otherwise
be almost invisible bumps along the x-axis, to be seen

The references given for logHist in David Scott's DistributionUtils
package are:

Barndorff-Nielsen, O. (1977) Exponentially decreasing distributions for 
the logarithm of particle size, Proc. Roy. Soc. Lond., A353, 401–419.

Barndorff-Nielsen, O. and Blæsild, P (1983). Hyperbolic distributions. 
In Encyclopedia of Statistical Sciences, eds., Johnson, N. L., Kotz, S. 
and Read, C. B., Vol. 3, pp. 700–707. New York: Wiley.

Fieller, N. J., Flenley, E. C. and Olbricht, W. (1992) Statistics of 
particle size data. Appl. Statist., 41, 127–146.


> Hadley
>
> On Sunday, August 29, 2010, Joshua Wiley<jwiley.psych at gmail.com>  wrote:
>> Hi Derek,
>>
>> Here is an option using the package ggplot2:
>>
>> library(ggplot2)
>> x<- sample(x = 10:50, size = 50, replace = TRUE)
>> qplot(x = x, geom = "histogram") + scale_y_log()
>>
>> However, the log scale is often inappropriate for histograms, because
>> the y-axis represents counts, which could potentially be 0, and
>> therefore undefined (R outputs -Inf).  Another option using base
>> graphics would be something along the lines (no pun intended) of:
>>
>> temp<- hist(x, plot = FALSE) #get histogram data
>> plot(x = temp$mids, y = log(temp$counts), type = "h")
>>
>> HTH,
>>
>> Josh
>>
>> On Sun, Aug 29, 2010 at 6:58 PM, Derek M Jones<derek at knosof.co.uk>  wrote:
>>> All,
>>>
>>> I have been trying to get calls to hist(...) to be plotted
>>> with the y-axis having a log scale.
>>>
>>> I have tried: par(ylog=TRUE)
>>>
>>> I have also looked at the histogram package.
>>>
>>> Suggestions welcome.
>>>
>>> --
>>> Derek M. Jones                         tel: +44 (0) 1252 520 667
>>> Knowledge Software Ltd                 mailto:derek at knosof.co.uk
>>> Source code analysis                   http://www.knosof.co.uk
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>>
>> --
>> Joshua Wiley
>> Ph.D. Student, Health Psychology
>> University of California, Los Angeles
>> http://www.joshuawiley.com/
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

-- 
Derek M. Jones                         tel: +44 (0) 1252 520 667
Knowledge Software Ltd                 mailto:derek at knosof.co.uk
Source code analysis                   http://www.knosof.co.uk



More information about the R-help mailing list