[R] y axis on hist

Bud Gibson fpgibson at umich.edu
Thu Dec 12 14:42:03 CET 2002


Let me try to clarify.  I would like an automated way to set the y axis 
to cover the largest count (or density) in one of the automatically 
computed bins.  I thought hist did this.  Working from Dalgaard's book 
example on writing a function, it would seem I could do something like:

y <- rnorm(100000)
h <- hist(y)
ylim <- range(0,max(h$counts))
hist(y,ylim=ylim)

and be assured that the y axis covered the data points.  However, it 
does not, and the behavior does not seem entirely systematic to me.

Bud

Daniel E. Ho wrote:

>From: "Bud Gibson" <fpgibson at umich.edu>
>  
>
>>The y axis on the hist function seems to set its limits oddly.
>>sometimes, it covers the full range of the data and sometimes it stops
>>one major tick short.  I have had this behavior with a variety of data
>>sets, and it can easily be reproduced by just running the following
>>several times:
>>
>>hist(rnorm(100000))
>>
>>I have tried explicitly setting ylim to the range of values produced by
>>rnorm (taking care to set some variable to rnorm(100000) and then
>>graphing that), and I still get the y axis plotting behvior I just
>>described.
>>    
>>
>
>I'm not sure I understand the problem correctly.  Doesn't the following seem
>to correct the y-axis problem?
>
>hist(rnorm(100000),ylim=c(0,25000))
>
>Dan
>daniel_ho at harvard.edu
>  
>




More information about the R-help mailing list