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? -- Robin Hankin Uncertainty Analyst Southampton Oceanography Centre SO14 3ZH tel +44(0)23-8059-7743 initialDOTsurname at soc.soton.ac.uk (edit in obvious way; spam precaution)
Try par(pty="s"). HTH, Andy> From: Robin Hankin > > 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? > > > > > -- > Robin Hankin > Uncertainty Analyst > Southampton Oceanography Centre > SO14 3ZH > tel +44(0)23-8059-7743 > initialDOTsurname at soc.soton.ac.uk (edit in obvious way; spam > precaution) > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >------------------------------------------------------------------------------Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system.
plot(x,y,asp=1, axes=F, bty="n");abline(0,1) #diagonal line misses corners axis(2, pos=0) axis(1, pos=0) hope this helps. spencer graves 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? > > > >
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
par(pty="s") is designed to set square plotting regions. (That is in `An Introduction to R', as well as used frequently in MASS.) plot(0:21, 0:21, type="n", xlab="x", ylab="x") points(x,y) abline(0,1) is one way to do it thereafter, as well as plot(x,y,xlim=lims,ylim=lims);abline(0,1) On Fri, 19 Mar 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? > > > > >-- 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 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On Fri, 2004-03-19 at 09:29, Marc Schwartz wrote:> On Fri, 2004-03-19 at 09:06, 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? > > This works for me: > > x <- 1:20 > y <- x + rep(c(-1, 1), 10) > lims <- range(c(x, y)) > plot(x, y, xlim = lims, ylim = lims, xaxs = "i", yaxs = "i") > abline(0, 1) > > # Plot region is square > >par("usr") > [1] 0 21 0 21 > > Here is a PS plot generated with: > > postscript(width = 5, height = 5) > plot(x, y, xlim = lims, ylim = lims, xaxs = "i", yaxs = "i") > abline(0, 1) > dev.off() > > http://www.MedAnalytics.com/Rplots.ps > > HTH, > > Marc SchwartzRobin, Sorry. It just dawned on me that you were not only referring to the line meeting the corners, but that the plot region itself by measurement was square, not just that the coordinates of the plot region were square. The following adjustment will work and I posted a new PS file at the same URL: # Set the plot region to be square par(pty = "s") plot(x, y, xlim = lims, ylim = lims, xaxs = "i", yaxs = "i") abline(0, 1) HTH, Marc Schwartz