[R] asp=1 and aspect ratio
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Fri Mar 19 16:33:32 CET 2004
Robin Hankin wrote:
>
> Hi everyone
>
> I want a square scatterplot with abline(0,1) going exactly through the
> SW and NE corners. By "square" I mean that the plotting region is
> exactly square, and that the axis limits are identical.
>
> x <- 1:20
> y <- x+rep(c(-1,1),10)
> lims <- range(c(x,y))
>
> None of the following do this:
>
> plot(x,y) ; abline(0,1) #not square
> plot(x,y,asp=1);abline(0,1) #diagonal line misses corners
>
> plot(x,y,asp=1,xaxs="i",yaxs="i");abline(0,1)
> #diagonal line misses corners
>
> plot(x,y,xaxs="i",yaxs="i");abline(0,1)
> #not square and diag misses corners
>
> plot(x,y,xlim=lims,ylim=lims,xaxs="i",yaxs="i");abline(0,1)
> #not square
>
> plot(x,y,asp=1,xlim=lims,ylim=lims,xaxs="i",yaxs="i");abline(0,1)
> #not square (plotting region about 8cm by 9.5cm)
>
>
>
> If I wrap the above lines in
>
> postscript(file="foo.ps", width=5,height=5)
> [...snip...]
> dev.off()
>
> then still none of the plots is exactly right [either one or both
> corners are missed, or the aspect ratio off]. What am I missing?
>
>
But the margins are all different which is throwing you off. How about:
par(mar = c(4, 4, 4, 4))
plot(x, y, asp = 1)
abline(0, 1)
HTH
-sundar
More information about the R-help
mailing list