Greetings, Folks. I'd appreciate being shown the way out of this one! I've been round the documentation in ever-drecreasing circles, and along other paths, without stumbling on the answer. The background to the question can be exemplified by the example (no graphics window open to start with): set.seed(54321) X0 <- rnorm(50) ; Y0 <- rnorm(50) par(mfrow=c(2,1),mfg=c(1,1),cex=0.5) plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), xlab="X",ylab="Y",main="My Plot",asp=1) par(mfg=c(2,1)) plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), xlab="X",ylab="Y",main="My Plot",asp=1) As you will see, both plots have been extended laterally to fill the plotting area horizontally, hence extend from approx X = -8 to approx X = +8 (on my X11 display), despite the xlim=c(-3,3); however, the "ylim=c(-3,3)" has been respected, as has "asp=1". What I would like to see, independently of the shape of the graphics window, is a pair of square plots, each with X and Y ranging from -3 to 3, even if this leaves empty space in the graphics window on either side. Hints? With thanks, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 08-Sep-10 Time: 20:01:19 ------------------------------ XFMail ------------------------------
'par mfrow' and not filling horizontally
8 messages · Greg Snow, William Dunlap, Marc Schwartz +4 more
Look at the squishplot function in the TeachingDemos package.
Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111 > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Ted Harding > Sent: Wednesday, September 08, 2010 1:01 PM > To: r-help at stat.math.ethz.ch > Subject: [R] 'par mfrow' and not filling horizontally > > Greetings, Folks. > I'd appreciate being shown the way out of this one! > I've been round the documentation in ever-drecreasing > circles, and along other paths, without stumbling on > the answer. > > The background to the question can be exemplified by > the example (no graphics window open to start with): > > set.seed(54321) > X0 <- rnorm(50) ; Y0 <- rnorm(50) > > par(mfrow=c(2,1),mfg=c(1,1),cex=0.5) > plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), > xlab="X",ylab="Y",main="My Plot",asp=1) > > par(mfg=c(2,1)) > plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), > xlab="X",ylab="Y",main="My Plot",asp=1) > > As you will see, both plots have been extended laterally > to fill the plotting area horizontally, hence extend from > approx X = -8 to approx X = +8 (on my X11 display), despite > the xlim=c(-3,3); however, the "ylim=c(-3,3)" has been > respected, as has "asp=1". > > What I would like to see, independently of the shape of > the graphics window, is a pair of square plots, each with > X and Y ranging from -3 to 3, even if this leaves empty > space in the graphics window on either side. > > Hints? > > With thanks, > Ted. > > -------------------------------------------------------------------- > E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> > Fax-to-email: +44 (0)870 094 0861 > Date: 08-Sep-10 Time: 20:01:19 > ------------------------------ XFMail ------------------------------ > > ______________________________________________ > 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.
Try par(pty="s"). Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Ted.Harding at manchester.ac.uk Sent: Wednesday, September 08, 2010 12:01 PM To: r-help at stat.math.ethz.ch Subject: [R] 'par mfrow' and not filling horizontally Greetings, Folks. I'd appreciate being shown the way out of this one! I've been round the documentation in ever-drecreasing circles, and along other paths, without stumbling on the answer. The background to the question can be exemplified by the example (no graphics window open to start with): set.seed(54321) X0 <- rnorm(50) ; Y0 <- rnorm(50) par(mfrow=c(2,1),mfg=c(1,1),cex=0.5) plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), xlab="X",ylab="Y",main="My Plot",asp=1) par(mfg=c(2,1)) plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), xlab="X",ylab="Y",main="My Plot",asp=1) As you will see, both plots have been extended laterally to fill the plotting area horizontally, hence extend from approx X = -8 to approx X = +8 (on my X11 display), despite the xlim=c(-3,3); however, the "ylim=c(-3,3)" has been respected, as has "asp=1". What I would like to see, independently of the shape of the graphics window, is a pair of square plots, each with X and Y ranging from -3 to 3, even if this leaves empty space in the graphics window on either side. Hints? With thanks, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 08-Sep-10 Time: 20:01:19 ------------------------------ XFMail ------------------------------
______________________________________________ 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.
On Sep 8, 2010, at 2:01 PM, Ted Harding wrote:
Greetings, Folks. I'd appreciate being shown the way out of this one! I've been round the documentation in ever-drecreasing circles, and along other paths, without stumbling on the answer. The background to the question can be exemplified by the example (no graphics window open to start with): set.seed(54321) X0 <- rnorm(50) ; Y0 <- rnorm(50) par(mfrow=c(2,1),mfg=c(1,1),cex=0.5) plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), xlab="X",ylab="Y",main="My Plot",asp=1) par(mfg=c(2,1)) plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), xlab="X",ylab="Y",main="My Plot",asp=1) As you will see, both plots have been extended laterally to fill the plotting area horizontally, hence extend from approx X = -8 to approx X = +8 (on my X11 display), despite the xlim=c(-3,3); however, the "ylim=c(-3,3)" has been respected, as has "asp=1". What I would like to see, independently of the shape of the graphics window, is a pair of square plots, each with X and Y ranging from -3 to 3, even if this leaves empty space in the graphics window on either side. Hints? With thanks, Ted.
Ted,
Try this:
set.seed(54321)
X0 <- rnorm(50) ; Y0 <- rnorm(50)
# add pty = "s"
par(mfrow=c(2, 1), mfg = c(1, 1), cex = 0.5,
pty = "s")
plot(X0, Y0, pch = "+", col = "blue",
xlim = c(-3, 3), ylim = c(-3, 3),
xlab = "X", ylab = "Y", main = "My Plot",
asp = 1)
par(mfg = c(2, 1))
plot(X0, Y0, pch = "+", col = "blue",
xlim= c(-3, 3), ylim = c(-3, 3),
xlab = "X", ylab = "Y", main = "My Plot",
asp = 1)
See ?par and 'pty', which defaults to "m".
HTH,
Marc Schwartz
Ted: ?layout Is this close to what you want? layout(matrix(1:2, nrow=2),wid=1,heigh=c(1,1), resp= TRUE) set.seed(54321) X0 <- rnorm(50) ; Y0 <- rnorm(50) plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), xlab="X",ylab="Y",main="My Plot",asp=1) plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), xlab="X",ylab="Y",main="My Plot",asp=1) On Wed, Sep 8, 2010 at 12:01 PM, Ted Harding
<Ted.Harding at manchester.ac.uk> wrote:
Greetings, Folks. I'd appreciate being shown the way out of this one! I've been round the documentation in ever-drecreasing circles, and along other paths, without stumbling on the answer. The background to the question can be exemplified by the example (no graphics window open to start with): ?set.seed(54321) ?X0 <- rnorm(50) ; Y0 <- rnorm(50) ?par(mfrow=c(2,1),mfg=c(1,1),cex=0.5) ?plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), ?xlab="X",ylab="Y",main="My Plot",asp=1) ?par(mfg=c(2,1)) ?plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), ?xlab="X",ylab="Y",main="My Plot",asp=1) As you will see, both plots have been extended laterally to fill the plotting area horizontally, hence extend from approx X = -8 to approx X = +8 (on my X11 display), despite the xlim=c(-3,3); however, the "ylim=c(-3,3)" has been respected, as has "asp=1". What I would like to see, independently of the shape of the graphics window, is a pair of square plots, each with X and Y ranging from -3 to 3, even if this leaves empty space in the graphics window on either side. Hints? With thanks, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 08-Sep-10 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Time: 20:01:19 ------------------------------ XFMail ------------------------------
______________________________________________ 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.
Bert Gunter Genentech Nonclinical Biostatistics 467-7374 http://devo.gene.com/groups/devo/depts/ncb/home.shtml
On 08-Sep-10 19:16:15, Bert Gunter wrote:
Ted: ?layout Is this close to what you want? layout(matrix(1:2, nrow=2),wid=1,heigh=c(1,1), resp= TRUE) set.seed(54321) X0 <- rnorm(50) ; Y0 <- rnorm(50) plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), xlab="X",ylab="Y",main="My Plot",asp=1) plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), xlab="X",ylab="Y",main="My Plot",asp=1)
Thanks Greg, William, Marc & Bert for the suggestions. It seems
that Bert's suggestion of 'layout' may work best for my real example
(the one I posted was a simple one). It is also necessary to add
par(pty="s").
Greg: I must study squishplot() -- it looks useful.
William, Marc: I had tried pty="s" in my real example (I inadvertently
omitted it from the dummy example I posted), but it still did not
work -- see Case B of the real example below.
Anyway, here is an instance of the real problem. DISCLAIMER: This
is being done as an "exploration of concept" and does not necessarily
represent my true state of mind ...
## Code common to all approaches (Alterbative continuations A and B):
library(MASS)
M <- 10 ; N <- 2 ; plur <- "'s"
set.seed(54321)
mu <- (-3)+6*(0:(M-1))/(M-1)
mu <- rep(mu, N) ## M evenly spaced on (-3,3)
Y <- matrix(rnorm(M*N,mean=mu),ncol=N) ## N Y's for each mu
KDE <- kde2d(x=mu, y=Y, h=2.5, n=100, lims=c(-5,5,-5,5,-5.0,5.0))
S.x <- KDE$x ; S.y <- KDE$y ; S.z <- KDE$z
## For each value of Y in the KDE grid, find the mu with max KDE:
Mxs <- numeric(100)
for(j in (1:100)){ Mxs[j] <- S.x[which(S.z[,j]==max(S.z[,j]))] }
## A: Using Bert's 'layout' approach with pty="s" as well:
layout(matrix(1:2, nrow=2),wid=1,height=c(1,1), resp=TRUE)
par(cex=0.5,pty="s")
plot(mu,Y,pch="+",col="blue",asp=1,xlim=c(-5,5),ylim=c(-5,5),
xlab="True mu", ylab="Sampled Y's",
main=paste("KDE for (mu,Y) ",
M," mu's, ",N," Y",plur," per mu",sep=""))
contour(S.x, S.y, S.z, nlevels=7, drawlabels=FALSE, add=TRUE)
lines(S.x,S.y,col="green")
for(j in (1:100)){ Mxs[j] <- S.x[which(S.z[,j]==max(S.z[,j]))] }
lines(Mxs,S.x,col="red")
plot(S.x[1:100],Mxs[1:100],asp=1,pch="+",col="red",
xlim=c(-5,5),ylim=c(-5,5),
xlab="Future Observed Y",ylab="MLE of mu by KDE",
main="MLE of mu by KDE for this Sim vs Future Y")
lines(c(-3,3),c(-3,3),col="green")
lines(c(-3,-3),c(-3,3)) ; lines(c( 3, 3),c(-3,3))
text(0,3.5,"<-- Range of True mu used -->")
##C: Using par(pty="s") with par(mfrow) leaving out 'layout':
plot.new()
par(mfrow=c(2,1),mfg=c(1,1),cex=0.5,pty="s")
plot(mu,Y,pch="+",col="blue",asp=1,xlim=c(-5,5),ylim=c(-5,5),
xlab="True mu", ylab="Sampled Y's",pty="s",
main=paste("KDE for (mu,Y) ",
M," mu's, ",N," Y",plur," per mu",sep=""))
contour(S.x, S.y, S.z, nlevels=7, drawlabels=FALSE, add=TRUE)
lines(S.x,S.y,col="green")
for(j in (1:100)){ Mxs[j] <- S.x[which(S.z[,j]==max(S.z[,j]))] }
lines(Mxs,S.x,col="red")
par(mfg=c(2,1))
plot(S.x[1:100],Mxs[1:100],asp=1,pch="+",col="red",
xlim=c(-5,5),ylim=c(-5,5),
xlab="Future Observed Y",ylab="MLE of mu by KDE",
main="MLE of mu by KDE for this Sim vs Future Y")
lines(c(-3,3),c(-3,3),col="green")
lines(c(-3,-3),c(-3,3)) ; lines(c( 3, 3),c(-3,3))
text(0,3.5,"<-- Range of True mu used -->")
#################################################
Anyway, thanks! It has helped.
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 08-Sep-10 Time: 21:39:53
------------------------------ XFMail ------------------------------
remove your asp=1 and try again to see if that is what you want. On Wed, Sep 8, 2010 at 3:01 PM, Ted Harding
<Ted.Harding at manchester.ac.uk> wrote:
Greetings, Folks. I'd appreciate being shown the way out of this one! I've been round the documentation in ever-drecreasing circles, and along other paths, without stumbling on the answer. The background to the question can be exemplified by the example (no graphics window open to start with): ?set.seed(54321) ?X0 <- rnorm(50) ; Y0 <- rnorm(50) ?par(mfrow=c(2,1),mfg=c(1,1),cex=0.5) ?plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), ?xlab="X",ylab="Y",main="My Plot",asp=1) ?par(mfg=c(2,1)) ?plot(X0,Y0,pch="+",col="blue",xlim=c(-3,3),ylim=c(-3,3), ?xlab="X",ylab="Y",main="My Plot",asp=1) As you will see, both plots have been extended laterally to fill the plotting area horizontally, hence extend from approx X = -8 to approx X = +8 (on my X11 display), despite the xlim=c(-3,3); however, the "ylim=c(-3,3)" has been respected, as has "asp=1". What I would like to see, independently of the shape of the graphics window, is a pair of square plots, each with X and Y ranging from -3 to 3, even if this leaves empty space in the graphics window on either side. Hints? With thanks, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 08-Sep-10 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Time: 20:01:19 ------------------------------ XFMail ------------------------------
______________________________________________ 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.
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100909/b07766e2/attachment.pl>