Henrik Andersson
2005-Jul-26 08:16 UTC
[R] Plot zooming i.e. changing ylim according to xlim
Dear R-gurus, I would like to zoom in a plot, e.g. I select a region on the x-axis and then I would like the ranges on the y-axis to change accordingly. Is it possible to do this with existing functions, or do I have to invent some data selection before plotting? See below a short example, where I select ylim with trial and error, which I want to avoid. Cheers, Henrik Andersson -------------------------------------------------------------------- ## Example -- in reality more numbers, no function x <- seq(0,20) y <- exp(-x) plot(y~x,type='l') ## Zoom in the end, to see what's happenning plot(y~x,type='l',xlim=c(19,20)) ## Try other ylim plot(y~x,type='l',xlim=c(19,20),ylim=c(0,1)) ## Not enough plot(y~x,type='l',xlim=c(19,20),ylim=c(0,1E-8)) ## Better --------------------------------------------- Henrik Andersson Netherlands Institute of Ecology - Centre for Estuarine and Marine Ecology P.O. Box 140 4400 AC Yerseke Phone: +31 113 577473 h.andersson at nioo.knaw.nl http://www.nioo.knaw.nl/ppages/handersson
Mulholland, Tom
2005-Jul-26 09:07 UTC
[R] Plot zooming i.e. changing ylim according to xlim
Search the archives for zoom and you will find plenty of answers on this question. RSiteSearch("zoom") Tom> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Henrik Andersson > Sent: Tuesday, 26 July 2005 4:16 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Plot zooming i.e. changing ylim according to xlim > > > Dear R-gurus, > > I would like to zoom in a plot, e.g. I select a region on the > x-axis and > then I would like the ranges on the y-axis to change accordingly. > > Is it possible to do this with existing functions, or do I have to > invent some data selection before plotting? > > See below a short example, where I select ylim with trial and error, > which I want to avoid. > > Cheers, Henrik Andersson > -------------------------------------------------------------------- > ## Example -- in reality more numbers, no function > x <- seq(0,20) > y <- exp(-x) > > plot(y~x,type='l') > > ## Zoom in the end, to see what's happenning > > plot(y~x,type='l',xlim=c(19,20)) > > ## Try other ylim > > plot(y~x,type='l',xlim=c(19,20),ylim=c(0,1)) > > ## Not enough > > plot(y~x,type='l',xlim=c(19,20),ylim=c(0,1E-8)) > > ## Better > --------------------------------------------- > Henrik Andersson > Netherlands Institute of Ecology - > Centre for Estuarine and Marine Ecology > P.O. Box 140 > 4400 AC Yerseke > Phone: +31 113 577473 > h.andersson at nioo.knaw.nl > http://www.nioo.knaw.nl/ppages/handersson > > ______________________________________________ > 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
Henrik Andersson
2005-Jul-26 09:13 UTC
[R] Plot zooming i.e. changing ylim according to xlim
>>Dear R-gurus, >> >>I would like to zoom in a plot, e.g. I select a region on the >>x-axis and >>then I would like the ranges on the y-axis to change accordingly. >> >>Is it possible to do this with existing functions, or do I have to >>invent some data selection before plotting? >> >>See below a short example, where I select ylim with trial and error, >>which I want to avoid.Mulholland, Tom wrote: > Search the archives for zoom and you will find plenty of answers on this question. > > RSiteSearch("zoom") > > Tom I looked there already, but I could only find interactive zooming, which is also nice, but I want a non-interactive function that automagically changes the y-axis to fit only the data specified in the part of the x-axis, or the other way around. I guess that was not very clear from my first post. - Henrik
Hi Not avoiding trial and error but you can do it interactively by point clicking on a plot.> replotfunction (x, y, type = "l") { body <- locator(2) plot(x, y, xlim = range(body$x), ylim = range(body$y), type = type) }>HTH Best regards Petr Pikal On 26 Jul 2005 at 10:16, Henrik Andersson wrote:> Dear R-gurus, > > I would like to zoom in a plot, e.g. I select a region on the x-axis > and then I would like the ranges on the y-axis to change accordingly. > > Is it possible to do this with existing functions, or do I have to > invent some data selection before plotting? > > See below a short example, where I select ylim with trial and error, > which I want to avoid. > > Cheers, Henrik Andersson > -------------------------------------------------------------------- > ## Example -- in reality more numbers, no function x <- seq(0,20) y <- > exp(-x) > > plot(y~x,type='l') > > ## Zoom in the end, to see what's happenning > > plot(y~x,type='l',xlim=c(19,20)) > > ## Try other ylim > > plot(y~x,type='l',xlim=c(19,20),ylim=c(0,1)) > > ## Not enough > > plot(y~x,type='l',xlim=c(19,20),ylim=c(0,1E-8)) > > ## Better > --------------------------------------------- > Henrik Andersson > Netherlands Institute of Ecology - > Centre for Estuarine and Marine Ecology > P.O. Box 140 > 4400 AC Yerseke > Phone: +31 113 577473 > h.andersson at nioo.knaw.nl > http://www.nioo.knaw.nl/ppages/handersson > > ______________________________________________ > 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.htmlPetr Pikal petr.pikal at precheza.cz
Well here is the better shot x <- seq(0,20) y <- exp(-x) plot(x,y, type="l") intervalx<-c(19,20) intervaly<-y[x%in%intervalx] plot(x,y, xlim=range(intervalx), ylim=range(intervaly), type="l") HTH Petr On 26 Jul 2005 at 11:13, Henrik Andersson wrote:> >>Dear R-gurus, > >> > >>I would like to zoom in a plot, e.g. I select a region on the > >>x-axis and > >>then I would like the ranges on the y-axis to change accordingly. > >> > >>Is it possible to do this with existing functions, or do I have to > >>invent some data selection before plotting? > >> > >>See below a short example, where I select ylim with trial and error, > >> which I want to avoid. > Mulholland, Tom wrote: > > Search the archives for zoom and you will find plenty of answers on > > this question. > > > > RSiteSearch("zoom") > > > > Tom > > I looked there already, but I could only find interactive zooming, > which > is also nice, but I want a non-interactive function that > automagically > changes the y-axis to fit only the data specified in the part of the > x-axis, or the other way around. I guess that was not very clear from > my first post. > > - Henrik > > ______________________________________________ > 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.htmlPetr Pikal petr.pikal at precheza.cz
Deepayan Sarkar
2005-Jul-26 19:02 UTC
[R] Plot zooming i.e. changing ylim according to xlim
On 7/26/05, Henrik Andersson <h.andersson at nioo.knaw.nl> wrote:> Dear R-gurus, > > I would like to zoom in a plot, e.g. I select a region on the x-axis and > then I would like the ranges on the y-axis to change accordingly. > > Is it possible to do this with existing functions, or do I have to > invent some data selection before plotting? > > See below a short example, where I select ylim with trial and error, > which I want to avoid. > > Cheers, Henrik Andersson > -------------------------------------------------------------------- > ## Example -- in reality more numbers, no function > x <- seq(0,20) > y <- exp(-x) > > plot(y~x,type='l') > > ## Zoom in the end, to see what's happenning > > plot(y~x,type='l',xlim=c(19,20))I tend to use constructs like plot(y~x,type='l', subset = x > 15) (18 is not very interesting). Deepayan