[R] relative frequency plot
Erik Iverson
iverson at biostat.wisc.edu
Thu Apr 27 20:44:16 CEST 2006
See ?truehist in the MASS package.
Philipp Pagel wrote:
> On Thu, Apr 27, 2006 at 10:48:39AM -0700, nlei at sfu.ca wrote:
>
>>Hi All,
>>
>>I want to use "hist" to get the relative frequency plot. But the range of
>>ylab is greater than 1,which I think it should be less than 1 since it
>>stands for the probability.
>>
>>I'm confused. Could you please help me with it?
>
>
> I was pretty confused by that, too at first. The solution is that
> freq=False cause hist to plot the DENSITY rather than frequency. And
> density is not necesssarily the same as relative frequency. Excerpt from
> ?hist:
>
> density: values f^(x[i]), as estimated density values. If
> 'all(diff(breaks) == 1)', they are the relative frequencies
> 'counts/n' and in general satisfy sum[i; f^(x[i])
> (b[i+1]-b[i])] = 1, where b[i] = 'breaks[i]'.
>
> If you want relative distance try something like this:
>
> myhist = hist(x,breaks=52, plot=F)
> myhist$counts = myhist$counts / sum(myhist$counts)
> plot(myhist,main=NULL,border=TRUE,xlab="days",xlim=c(0,6),lty=2)
>
> Not exactly clean, though -- we are messing with the myhist object...
>
>
> cu
> Philipp
>
More information about the R-help
mailing list