From: Karen Chiswell <karenc2204_at_yahoo.com>

Date: Thu 05 Apr 2007 - 17:12:44 GMT

> > It's here! Your new message!

*> > Get new email alerts with the free Yahoo! Toolbar.
*

*> >
*

*> > ______________________________________________
*

*> > R-help@stat.math.ethz.ch mailing list
*

*> > https://stat.ethz.ch/mailman/listinfo/r-help
*

*> > PLEASE do read the posting guide
*

*> http://www.R-project.org/posting-guide.html
*

*> > and provide commented, minimal, self-contained,
*

*> reproducible code.
*

*> >
*

*>
*

The fish are biting.

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Apr 06 03:31:10 2007

Date: Thu 05 Apr 2007 - 17:12:44 GMT

Thanks for two nice & simple solutions.

I did not know about recordPlot() or replayPlot(). Unfortunately these do not give me quite what I want because I need (for use in another function) an object of class "lattice". I should have mentioned this part earlier!

However, your first solution using xyplot() works and I think it is a bit better than what I'm currently using.

Thanks!

Karen

- Gabor Grothendieck <ggrothendieck@gmail.com> wrote:

> Try this:

*>
**> x <- 1:100
**> xyplot(dnorm(x, 50, 10) + dnorm(x, 55, 12) +
**> dnorm(x, 60, 15) ~ x, type = "l")
**>
**> By the way, you can save classic graphics, at least
**> on windows, like this:
**>
**> ### your code
**> parms <-
**>
*

data.frame(ID=c(1,2,3),mu=c(50,55,60),sigma=c(10,12,15))

*>
*

curve(dnorm(x,mean=parms$mu[1],sd=parms$sigma[1]),from=0,

*> to=150, ylab="density", col="red")
**>
*

curve(dnorm(x,mean=parms$mu[2],sd=parms$sigma[2]),from=0,

*> to=150, ylab="density", col="blue", add=TRUE)
**>
*

curve(dnorm(x,mean=parms$mu[3],sd=parms$sigma[3]),from=0,

*> to=150, ylab="density", col="forestgreen", add=TRUE)
**> ###
**>
*

> myplot <- recordPlot()

*> title("Title A")
**>
**> # replay the plot with Title B
**> replayPlot(myplot)
**> title("Title B")
**>
**>
**>
**> On 4/5/07, Karen Chiswell <karenc2204@yahoo.com>
**> wrote:
**> > Hi List,
**> >
**> > I would like to plot multiple curves (parametric
**> > density curves) in one plot.
**> >
**> > For example:
**> > # parameters for three normal density curves
**> > parms =
**> >
**>
*

data.frame(ID=c(1,2,3),mu=c(50,55,60),sigma=c(10,12,15))

*> >
*

> > # I can easily draw three normal density curves

*> using
**> > curve():
**> >
**>
*

curve(dnorm(x,mean=parms$mu[1],sd=parms$sigma[1]),from=0,

*> > to=150, ylab="density", col="red")
**> >
**>
*

curve(dnorm(x,mean=parms$mu[2],sd=parms$sigma[2]),from=0,

*> > to=150, ylab="density", col="blue", add=TRUE)
**> >
**>
*

curve(dnorm(x,mean=parms$mu[3],sd=parms$sigma[3]),from=0,

*> > to=150, ylab="density", col="forestgreen",
*

> add=TRUE)

*> >
**> > but I would like to use lattice graphics (even
**> though
**> > I only want one panel) because I want to save the
**> > resulting plot in an object.
**> >
**> > I could create a dataframe that contains the
**> values I
**> > want to plot, and then plot using xyplot(). For
**> > example,
**> >
**> > x = seq(from=0, to=150, length=100)
**> > plot.df = data.frame(ID=rep(parms$ID,each=100),
**> >
**>
*

x=rep(x,3),mu=rep(parms$mu,each=100),sigma=rep(parms$sigma,each=100))

> > plot.df$d =

*> > dnorm(plot.df$x,mean=plot.df$mu,sd=plot.df$sigma)
**> >
**> > require(lattice)
**> > p=xyplot(d~x, data=plot.df, groups=ID, type="l")
**> >
**> > However... is there a more elegant/efficient way
**> to
**> > do this? I have tried using the panel.curve panel
**> > function (with xyplot() and histogram()), but I am
**> not
**> > very experienced with using panel functions (or R
**> > actually), and I haven't had any success with this
**> > yet.
**> >
**> > Many thanks for any suggestions,
**> > Karen
**> >
**> > -------------------------------
**> > Karen Chiswell
**> > Department of Statistics
**> > North Carolina State University
**> > -------------------------------
**> >
**> >
**> >
**> >
**> >
**>
*

> > It's here! Your new message!

The fish are biting.

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Apr 06 03:31:10 2007

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Thu 05 Apr 2007 - 18:30:45 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*