Re: R-beta: adjusting y-axis scale with multiple lines in plot
Douglas Bates (bates@stat.wisc.edu)
06 May 1998 07:49:16 -0500
To: Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk>
Subject: Re: R-beta: adjusting y-axis scale with multiple lines in plot
From: Douglas Bates <bates@stat.wisc.edu>
Date: 06 May 1998 07:49:16 -0500
In-Reply-To: Peter Dalgaard BSA's message of 06 May 1998 13:45:06 +0200
Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:
> mjantti@abo.fi writes:
>
> > Or is the procedure to be used to first estimate all densities, the plot
> > the first one with 'ylim=c(0,max())' and the add the lines one by one?
> > If anyone has pondered on and solved this, I'd be very grateful for the
> > solution.
>
> Yup. That's the general procedure. Some kind of autoscaling would be
> nice to have some time in the future, but currently the graphics
> model in R (and S-plus) is that of a hardcopy device (e.g. a plotter)
> with "no eraser".
A general approach when overlaying several separate lines on a plot is
to calculate all the lines first then plot the concatenated y
coordinates versus the concatenated y coordinates using the graphical
argument type="n". That establishes the axes as large enough to
accomodate all the data but does not draw any points or lines.
After that you can add the individual lines with the lines function.
It would look like
samp <- rnorm(50)
d1 <- density(samp)
d2 <- density(samp, adj = 0.5)
d3 <- density(samp, adj = 2.0)
plot( c(d1$x, d2$x, d3$x), c(d1$y, d2$y, d3$y), type = "n")
lines( d1$x, d1$y, lty = 2 ) # maybe lines(d1, lty = 2) would work
lines( d2$x, d2$y, lty = 3 )
lines( d3$x, d3$y, lty = 4 )
--
Douglas Bates bates@stat.wisc.edu
Statistics Department 608/262-2598
University of Wisconsin - Madison http://www.stat.wisc.edu/~bates/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._