[R] superimposing graphs

Dirk Eddelbuettel edd at debian.org
Sat Apr 19 02:30:49 CEST 2003


On Fri, Apr 18, 2003 at 07:22:58PM -0400, Faheem Mitha wrote:
> In the function below, I call truehist and curve, but these are plotted in
> different figures.
> 
> I'd like them to be plotted on the same figure, and to use common axes, of
> course. Can anyone suggest a simple, robust way to do this? I'd prefer not
> to do micro-fiddling of graphical parameters if possible.

Here is one way with an estimated density function, IIRC more a less a copy
of what is in MASS.

> library(MASS)
> X<-rt(250,2)
> Xdensity <- density(X, width=width.SJ(X, method="dpi"), n=200)
> truehist(X, col="lightgray", ymax=max(Xdensity$y))
> lines(Xdensity)
> title(main="Histogram and Density")
> box()

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

Hth,  Dirk

-- 
Don't drink and derive. Alcohol and algebra don't mix.



More information about the R-help mailing list