[R] Histogram Bar Spacing or Border Width

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Feb 9 22:48:03 CET 2005


A hint: hist() does no plotting.  That is done by the "histogram" method 
of plot(), which you can copy and modify to your own needs/desires.
Alternatively you can create myplot() and call

myplot(hist(..., plot=TRUE), ...)

On Wed, 9 Feb 2005, Thomas Hopper wrote:

> I understand the problem from a statistical perspective, and you make an 
> excellent point (as I have come to expect, reading this list). However, I'm 
> thinking about it from a visual/aesthetic perspective.
>
> Let me try this. Plot two histograms side-by-side:
>
>> x <- rnorm(10)
>> par(mfcol=c(1,2))
>> hist(x)
>> hist(x,col="gray",border="gray")
>
> Which one is easier to interpret? To my eyes, the default hist() is, but 
> given the statistical meaning of a histogram, I think I could argue that the 
> gray version is a more accurate representation of the data.
>
> The default histogram delimits the space between subareas to make the graph 
> easier to read. I'm just trying to tweak this to further improve it. I don't 
> want to separate the bars so much as control (and, I hope, improve) their 
> appearance.
>
> Thanks,
>
> Tom
>
> On Feb 9, 2005, at 11:06 AM, Prof Brian Ripley wrote:
>
>> A histogram is a density estimate (at least as defined in the Encyclopedia 
>> of Statistics Sciences, if not in many US Universities).  It is an area, 
>> not a series of unrelated bars, so it makes no sense to have spaces between 
>> the subareas.
>> 
>> Unfortunately, hist() will also produce barplots of counts.
>> 
>> On Wed, 9 Feb 2005, Thomas Hopper wrote:
>> 
>>> Is there any way to control the spacing between bars in a histogram, or 
>>> change the border width (I'm assuming the hist() function, though 
>>> alternatives are welcome)? I'm interested in changing the visual spacing 
>>> between columns in a plotted histogram.
>>> 
>>> The general effect I'm looking for can be accomplished in barplots using 
>>> the "width=" parameter, but I have not been able to find a way to adjust 
>>> the apparent spacing in histograms.
>> 
>> -- 
>> Brian D. Ripley,                  ripley at stats.ox.ac.uk
>> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
>> University of Oxford,             Tel:  +44 1865 272861 (self)
>> 1 South Parks Road,                     +44 1865 272866 (PA)
>> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>> 
>> 
> ---
> In cyberspace, no one can hear you scream.
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list