[R] asp and ylim

From: David Epstein <David.Epstein_at_warwick.ac.uk>
Date: Sun, 20 Jul 2008 18:27:19 +0100

#See David Williams' book "Weighing the odds", p286

y <- c(1.21, 0.51, 0.14, 1.62, -0.8,

         0.72, -1.71, 0.84, 0.02, -0.12) ybar <- mean(y)
ylength <- length(y)
ybarv <- rep(ybar, ylength)
x <- 1:ylength
plot(x,y,asp=1,xlab="position",ylab="ybar",type="n",ylim=c(-1,1)) segments(x[1], ybar, x[ylength], ybar)
points(x, ybarv, pch=21, bg="white")

With asp=1, the value of ylim seems to be totally ignored, as in the above code. With asp not set, R plays close attention to the value of ylim. This is not intuitive behaviour, or is it?

How can I set the aspect ratio, and simultaneously set the plot region? The aspect ratio is one number and the plot region is given by four numbers (xleft, xright, yleft, yright). Logically, these 5 numbers are independent of each other and arbitrary, provided xleft<xright and yleft<yright. This should give a one-to-one bijection between 5-tuples and plots, determined up to a change of scale that is uniform in the x- and y-dirctions. My code above shows the (to me) obvious attempt, which fails.


R-help_at_r-project.org 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. Received on Sun 20 Jul 2008 - 17:39:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 21 Jul 2008 - 18:32:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive