[R] superimposing graphs

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Sat Apr 19 11:08:57 CEST 2003


Dirk Eddelbuettel <edd at debian.org> writes:

> On Fri, Apr 18, 2003 at 07:22:58PM -0400, Faheem Mitha wrote:

> Peter has another solution in ISwR, but that may have been particular to a
> Normal distribution, and my copy is at work anyway.

(The scripts are in the ISwR package, though... End of Section 1.3 and
beginning of 1.4.) The basic principle is this

h <- hist(x, plot=F)
ylim <- range(0, h$density, dnorm(0))
hist(x, freq=F, ylim=ylim)
curve(dnorm(x), add=T)

The main point is to keep both the histogram and the curve on scale,
so it does rely on knowing that the max of the normal density is at
the mean. For an empirical density, you'll have to find its maximum
empirically, but otherwise the same technique applies.

-- 
   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