[R] histograms - function hist() - problems in R 2.13.1

Duncan Murdoch murdoch.duncan at gmail.com
Sun Jul 17 20:26:31 CEST 2011

On 11-07-17 1:17 PM, Paulo Barata wrote:
> Dear R-list members,
> I would like to report some problems, in R 2.13.1, with the function
> hist(), which constructs histograms.
> Sample code:
> x<- rnorm(1000)
> hist(x, breaks=16)
> In R 2.13.1, in the histogram so produced, the bottom of the bars
> are not exactly aligned in a perfect horizontal, there is an up-and-down
> pattern among the bottom lines of the bars. Also, the vertical sides of
> the bars do not align properly, so there is some superposition of
> the bars, they are not always located exactly side to side. It seems
> that some bars (each one a rectangle by itself) are somehow displaced
> from their ideal positions.
> This problem happens in both the 32-bit and 64-bit versions
> of R 2.13.1. Histograms produced through R 2.13.0 are perfectly
> constructed, without any problems. I can provide a pdf file
> on request, which shows a histogram graph with the problems.
> I use R.2.13.1 (both 32-bit and 64-bit) on Windows 7 Professional
> 64-bit.

This is a result of the fix to bug PR#14583.  The problem there was that 
one-pixel rectangles would sometimes disappear.  Unfortunately, 
guaranteeing that they are large enough to see means that sometimes 
bigger ones are made larger as well, so some of the rectangles are 
increased by one pixel below the axis.

I'll see if I can find a better fix.  I think it will be easy to 
guarantee that the bottoms line up, but then the tops might not in some 
other graphic.

Duncan Murdoch

More information about the R-help mailing list