[R] subplot strange behavoir

Greg Snow Greg.Snow at imail.org
Wed Oct 5 22:30:44 CEST 2011


When I copy and paste your code I get what is expected, the 2 subplots line up on the same y-value.  What version of R are you using, which version of subplot? What platform?

-- 
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 emorway
> Sent: Wednesday, October 05, 2011 1:40 PM
> To: r-help at r-project.org
> Subject: [R] subplot strange behavoir
> 
> Hello,
> 
> Below is some example code that should reproduce an error I'm
> encountering
> while trying to create a tiff plot with two subplots.  If I run just
> the
> following bit of code through the R GUI the result is what I'd like to
> have
> appear in the saved tiff image:
> 
> x<-seq(0:20)
> y<-c(1,1,2,2,3,4,5,4,3,6,7,1,1,2,2,3,4,5,4,3,6)
> plot(x,y,type="l",las=1,ylim=c(0,12))
> subplot(edm.sub(x[seq(1:5)],y[seq(1:5)]),x=4,y=9,size=c(1,1.5))
> subplot(edm.sub(x[seq(15,20,by=1)],y[seq(15,20,by=1)]),x=17,y=9,size=c(
> 1,1.5))
> 
> However, if expanding on this code with:
> 
> edm.sub<-function(x,y){plot(x,y,col="red",frame.plot=F,
>                        las=1,xaxs="i",yaxs="i",type="b",
>                        ylim=c(0,6),xlab="",ylab="")}
> 
> png("c:/temp/lookat.tif",res=120,height=600,width=1200)
> layout(matrix(c(1,2),2,2,byrow=TRUE),c(1.5,2.5),respect=TRUE)
> plot(seq(1:10),seq(1:10),type="l",las=1,col="blue")
> plot(x,y,type="l",las=1,ylim=c(0,12))
> subplot(edm.sub(x[seq(1:5)],y[seq(1:5)]),x=4,y=9,size=c(1,1.5))
> subplot(edm.sub(x[seq(15,20,by=1)],y[seq(15,20,by=1)]),x=17,y=9,size=c(
> 1,1.5))
> dev.off()
> 
> One will notice the second subplot is out of position (notice the
> y-coordinate is the same for both subplots...y=9):
> http://r.789695.n4.nabble.com/file/n3875917/lookat.png
> 
> If I try to 'guess' a new y-coordinate for the second subplot, say
> y=10:
> 
> png("c:/temp/lookat.tif",res=120,height=600,width=1200)
> layout(matrix(c(1,2),2,2,byrow=TRUE),c(1.5,2.5),respect=TRUE)
> plot(seq(1:10),seq(1:10),type="l",las=1,col="blue")
> plot(x,y,type="l",las=1,ylim=c(0,12))
> subplot(edm.sub(x[seq(1:5)],y[seq(1:5)]),x=4,y=9,size=c(1,1.5))
> subplot(edm.sub(x[seq(15,20,by=1)],y[seq(15,20,by=1)]),x=17,y=10,size=c
> (1,1.5))
> dev.off()
> 
> R kicks back the following message
> Error in plot.new() : plot region too large
> 
> Am I mis-using subplot?
> 
> Thanks, Eric
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/subplot-
> strange-behavoir-tp3875917p3875917.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.



More information about the R-help mailing list