[R] log y 'axis' of histogram

Hadley Wickham hadley at rice.edu
Mon Aug 30 14:11:41 CEST 2010


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.

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.
>

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list