[R] Overlaying Plots
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Thu Nov 18 08:21:24 CET 1999
On Wed, 17 Nov 1999, Neil E. Klepeis wrote:
> Greetings,
>
> Problem Summary: I am trying to overlay data series by plotting on the
> same set of axes, but the ylim and xlim specifications apparently do not
> specify the actual limits of the plot. Is there some way to specify the
> x and y limits that I am overlooking? Or is there a bug? Or.....
>
> According to V&R (1999, p. 71), one should "use the same xlim or ylim
> (or both) setting on each plot...". Unfortunately, this does not work
> in R.
You need to heed the rest of the sentence, which is an important caveat
(especially over xaxs).
> When I enter the following:
>
> > x<-rnorm(1000)
> > qqnorm(x,ylim=range(x))
> > range(x)
> [1] -3.222694 3.253103
> > qqnorm(x,ylim=c(-3,3))
>
> ...the actual plot y limit is not [-3.222692, 3.253103] or [-3,3]. R
> sets the extreme tic marks in the second case, and some other
> (seemingly) arbitrary limits in the first case (presumably to fit all
> the data on the plot with a bit of a margin).
Yes, this is done by par(xaxs), which is implemented in R despite the
current documentation. Try xaxs="i" if you want exact limits. In both
cases the computed limits are increased when using the default yaxs="r",
by 4% if I recall correctly.
However, this is not an example where our advice does not work. We say
you need to set the _same_ limits, and that does usually work unless
R messes internally with xaxs or yaxs (and boxplot does, for example)
or tries to set a square plot or ....
> I've had to make due with the situation by setting whole numbers as the
> limits (e.g., the extreme tic marks):
>
> >par(ann=F,new=T)
> >oldylim<-par()$yaxp
> >ylim[2] <- oldylim[2]
> >ylim[1] <- oldylim[1]
>
> But this doesn't always work for me and is less than satisfactory.
>
> Please advise.
yaxs="i" is the key, I think. It is quite possible that there are problems
in R here, so we would be interested in seeing examples which go wrong.
--
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list