[Rd] Determining the break points by hist() leads to errors (PR#2432)

volker.franz@tuebingen.mpg.de volker.franz@tuebingen.mpg.de
Wed Jan 8 19:12:03 2003


Hi,

if I dermine the break points using the hist() function and then try
to re-use these in a new histogram, R fails. Here is an example of the
problem:

##First, plot a histogram: 
data(islands)
foo <- hist(islands,freq=T)

##Now, try plot it again, with the previously determined break points:
hist(islands,breaks=foo$breaks,freq=T)

##... this lead to the warning message:
Warning message: 
the AREAS in the plot are wrong -- rather use `freq=FALSE'!
in: plot.histogram(r, freq = freq, col = col, border = border, angle = 

##The reason for this seems to be, that the breaks are NOT 
##equidistant (despite foo$equidist being TRUE!):

> foo$breaks
[1]    -0.0018  2000.0018  4000.0018  6000.0018  8000.0018 10000.0018
[7] 12000.0018 14000.0018 16000.0018 18000.0018

##Correcting this (by changing the first element of foo$breaks):
corr.breaks <- c(+0.0018,2000.0018,4000.0018,6000.0018,8000.0018,
                 10000.0018,12000.0018,14000.0018,16000.0018,18000.0018)

##...leads to the desired result:
hist(islands,breaks=corr.breaks,freq=T)

Best
Volker

--please do not edit the information below--
Version:
 platform = i386-pc-linux-gnu
 arch = i386
 os = linux-gnu
 system = i386, linux-gnu
 status = 
 major = 1
 minor = 5.1
 year = 2002
 month = 06
 day = 17
 language = R

Search Path:
 .GlobalEnv, package:ctest, Autoloads, package:base