Skip to content
Back to formatted view

Raw Message

Message-ID: <20030419003049.GA25335@sonny.eddelbuettel.com>
Date: 2003-04-19T00:30:49Z
From: Dirk Eddelbuettel
Subject: superimposing graphs
In-Reply-To: <Pine.LNX.4.44.0304181845500.4959-100000@Chrestomanci>

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.