[R] histogram plot as step function

David Scott d.scott at auckland.ac.nz
Thu Nov 15 11:21:14 CET 2007


On Thu, 15 Nov 2007, Hakim Tafer wrote:

> Hi
>
> I want to plot a histogram (not cumulative!) as a step-function.
> Any idea how achieve this?
>
> Thank you
>

Well if I understand you correctly you can do this.

x<-rnorm(100)
par(mfrow=c(2,1))
hist(x)
histRes <- hist(x,plot=FALSE)
xvals <- histRes$breaks
yvals <- histRes$counts
length(xvals)
length(yvals)
xvals <- c(xvals,xvals[length(xvals)])
yvals <- c(0,yvals,0)
plot(xvals,yvals,type="S")

David Scott
_________________________________________________________________
David Scott	Department of Statistics, Tamaki Campus
 		The University of Auckland, PB 92019
 		Auckland 1142,    NEW ZEALAND
Phone: +64 9 373 7599 ext 86830		Fax: +64 9 373 7000
Email:	d.scott at auckland.ac.nz

Graduate Officer, Department of Statistics
Director of Consulting, Department of Statistics



More information about the R-help mailing list