[R] Histogram without common borders

Thomas Petzoldt thpe at hhbio.wasser.tu-dresden.de
Tue Jul 20 07:52:06 CEST 2004


Ross Darnell wrote:
> Is it possible to produce a histogram directly using the hist()
> function with the common borders removed?
> 
> It can be done by plotting the histogram object using type 's'teps.
> 
> my.hist <- hist(x,plot=FALSE)
> plot(my.hist$breaks,c(0,my.hist$counts),type='s')

Hello Ross,

I think, your approach is not too bad, however you should use "S" 
instead of "s", see:

my.hist <- hist(x, lty=1)
lines(my.hist$breaks,c(0, my.hist$counts),
       type='S', lty="dotted", col="red")

avoiding unwanted vertical lines with:

my.hist <- hist(x, lty=0)
lines(c(my.hist$breaks, max(my.hist$breaks)),
       c(0,my.hist$counts,0), type='S')

OR simply use filled bars:

hist(x, col="grey", lty=0)

Hope it helps

Thomas P.




More information about the R-help mailing list