[R] Overlaying graphs

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed Sep 3 18:23:29 CEST 2003

"Paul Meagher" <paul at datavore.com> writes:

> I am wanting to construct a probability distribution for height and then,
> hopefully, visually and analytically demonstrate that it is normally
> distributed.
> These are the commands I have developed so far:
> fat   <- read.table("fat.dat", header=TRUE)
> mu    <- mean(fat$height)
> sdev  <- sd(fat$height)
> hist(fat$height, br=20, freq=FALSE, xlab="Male Height in Inches")
> curve(dnorm(x, mu, sdev), from=64, to=78)
> I do not know how to overlay the curve graphic on top of hist graphic.
> I am hoping to show visually that the normal curve overlays the obtained
> probability distribution when plotted on the same graph.  Unfortunately, I
> an not sure how to overlay them. Can anyone point me in the right direction
> or show me the code.

Using the "add" argument to curve gets you most of the way, but
getting the y axis right is a little tricky. You could take a look at
the scripts in the ISwR package (sec.1.3), or the book itself...

   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907

More information about the R-help mailing list