R-beta: adjusting y-axis scale with multiple lines in plot
Douglas Bates
bates at stat.wisc.edu
Wed May 6 14:49:16 CEST 1998
Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> writes:
> mjantti at 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 at 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 at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list