[R] subplot strange behavoir

emorway emorway at usgs.gov
Wed Oct 5 21:40:03 CEST 2011


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.



More information about the R-help mailing list