# [R] plot() axis problem

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jul 27 12:22:34 CEST 2001

```On Fri, 27 Jul 2001, Petr Pikal wrote:

>
>
> On 23 Jul 2001, at 11:18, Bill Simpson wrote:
>
> > >
> > > The example uses a rather artificial dataset, neatly divided into
> > > monotonically increasing low and high values.  Any permutation of
> > > those values that did not fall into that pattern would render the
> > > question meaningless.  For example, try
> > The example I posted was artificial because my real example had 10,000
> > pts and I didn't want to post that. Basically I wanted to look at the
> > region surrounding one frequency of the spectrum where I expected a
> > peak. I couldn't see the peak because plot() had used the whole set of
> > data to pick the range for the y-axis.
> >
> > There was of course a nice peak but it was invisible because this peak
> > was maybe 1/1000 as high as the maximum peak in the whole spectrum.
> >
> Sorry to to join this thread so late but I was occupied and did not
> read my post a while.
>
> I deal with similar sets of data with peaks and I use quite short
> function for interactive zooming.
>
> Here it is:
>
> replot_function(x,y)
> {
> body_locator(2)
> dmx_min(body\$x)
> hmx_max(body\$x)
> dmy_min(body\$y)
> hmy_max(body\$y)
> plot(x,y,xlim=c(dmx,hmx),ylim=c(dmy,hmy),type="l")
> }

range() will enable you to simplify this considerably.  Using the space
bar might make it readable.  (The recommended assignment operator is <- :
if you must use _ at least have spaces around it.  See Writing R
Extensions chapter 3 for how to tidy up your R source code.)

replot <- function(x, y, type="l")
{
body <- locator(2)
plot(x, y, xlim=range(body\$x), ylim=range(body\$y), type=type)
}

>
> It has to be called after plotting x,y and you shall pinpoint to opposit
> corners. I call it repetitively without any problems. Maybe it can help
> you.
>
> > >
> > > I think the present behavior of plot() is pretty sensible.
> > If you look around at other plotting programs out there I think you'll
> > see some doing what I propose. I think if you use small datasets the
> > current plot() behaviour will not cause problems. It's only a pain
> > once you start zooming in on small stretches.
> >
> > Bill
> >
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> > -.-.-.-.- 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
> > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> > _._._._._
>
>
> Petr
>
> petr.pikal at precheza.cz
> p.pik at volny.cz
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

--
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```