Sorry if this is an obvious question but I have not been able to find the answer. I wish to plot 3 lines on the same plot. However, whichever one I plot first, the axis does not have a big enough range for the other two to be shown in the plot (they get cut off at the top and the bottom). Is there a way to change the range of the y-axis when adding a new line to the plot? Thank you, Alex
You need to sed the ylim parameter in the plot function to the range that you need. Cheers, Thierry ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx op inbo.be www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney> -----Oorspronkelijk bericht----- > Van: r-help-bounces op stat.math.ethz.ch > [mailto:r-help-bounces op stat.math.ethz.ch] Namens webb op stats.ox.ac.uk > Verzonden: vrijdag 23 maart 2007 13:41 > Aan: r-help op stat.math.ethz.ch > Onderwerp: [R] Change Axis Size > > Sorry if this is an obvious question but I have not been able > to find the answer. > I wish to plot 3 lines on the same plot. However, whichever > one I plot first, the axis does not have a big enough range > for the other two to be shown in the plot (they get cut off > at the top and the bottom). Is there a way to change the > range of the y-axis when adding a new line to the plot? > > Thank you, > > Alex > > ______________________________________________ > R-help op 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. >
On Fri, 2007-03-23 at 12:40 +0000, webb at stats.ox.ac.uk wrote:> Sorry if this is an obvious question but I have not been able to find the > answer. > I wish to plot 3 lines on the same plot. However, whichever one I plot > first, the axis does not have a big enough range for the other two to be > shown in the plot (they get cut off at the top and the bottom). Is there a > way to change the range of the y-axis when adding a new line to the plot? > > Thank you, > > AlexUse the ylim parameter in plot(): x <- 1:100 y1 <- sort(runif(100)) y2 <- y1 * 1.2 y3 <- y2 * rnorm(100) plot(x, y1, type = "n", ylim = range(y1, y2, y3)) lines(x, y1, col = "red") lines(x, y2, col = "blue") lines(x, y3, col = "green") An alternative is matplot: matplot(x, cbind(y1,y2,y3), col = c("red", "blue", "green"), type = "l", lty = "solid") or matplot(x, cbind(y1,y2,y3), type = "n") matlines(x, cbind(y1,y2,y3), col = c("red", "blue", "green"), lty = "solid") HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
I think that technically the answer is no. What you need to do is set the size of the appropriate axis with the first plot command ( xlim = or ylim = Have a look at ?plot.default --- webb at stats.ox.ac.uk wrote:> Sorry if this is an obvious question but I have not > been able to find the > answer. > I wish to plot 3 lines on the same plot. However, > whichever one I plot > first, the axis does not have a big enough range for > the other two to be > shown in the plot (they get cut off at the top and > the bottom). Is there a > way to change the range of the y-axis when adding a > new line to the plot? > > Thank you, > > Alex > > ______________________________________________ > R-help at 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. >