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.
subplot strange behavoir
7 messages · Sarah Goslee, Greg Snow, Morway, Eric
Hi,
I'm assuming you're using subplot() from Hmisc, but it's a good idea
to specify.
It's not subplot() that's causing the problem, it's layout, or rather the
interaction between the two.
This section run at the command line doesn't work:
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))
You appear to have run afoul of two things:
from ?subplot
Any graphical parameter settings that you would like to be in
place before ?fun? is evaluated can be specified in the ?pars?
argument (warning: specifying layout parameters here (?plt?,
?mfrow?, etc.) may cause unexpected results).
and from ?layout
These functions are totally incompatible with the other mechanisms
for arranging plots on a device: ?par(mfrow)?, ?par(mfcol)? and
?split.screen?.
And also apparently subplot().
You could try asking the package maintainer, but I think you may be
better off making two separate figures. Or you could delve into the
mysteries of par(), of course.
Incidentally, you can't use png() to make a tif, no matter what you call
it. You probably want tiff() instead.
Sarah
On Wed, Oct 5, 2011 at 3:40 PM, emorway <emorway at usgs.gov> wrote:
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
Sarah Goslee http://www.functionaldiversity.org
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.
Hello Greg, Session info is below. Running Win7 64-bit. I just upgraded my version of R and tried rerunning the code and got the same odd result. I, too, get an expected result when I create the plot in the R GUI. The problem crops up only when I try and create the plot in png() or tiff(). Perhaps I need to try par(new=T), or some other trick-of-the-trade? If you're unable to recreate the problem, I suppose this is nearly a dead-end? sessionInfo() R version 2.13.2 (2011-09-30) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] splines stats graphics grDevices utils datasets methods base other attached packages: [1] TeachingDemos_2.7 Hmisc_3.8-3 survival_2.36-9 loaded via a namespace (and not attached): [1] cluster_1.14.0 grid_2.13.2 lattice_0.19-33 tools_2.13.2 -- View this message in context: http://r.789695.n4.nabble.com/subplot-strange-behavoir-tp3875917p3876178.html Sent from the R help mailing list archive at Nabble.com.
I tried this trick, and clearly things are not going in the right direction.
It seems 'layout' is at the root of my frustration, so I can make two plots
and marge them in adobe illustrator (or something similar).
png("c:/temp/lookat.png",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))
par(new=T)
plot(x,y,las=1,ylim=c(0,12),type="n",ann=F,las=1,col="blue")
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()
http://r.789695.n4.nabble.com/file/n3876285/lookat.png
--
View this message in context: http://r.789695.n4.nabble.com/subplot-strange-behavoir-tp3875917p3876285.html
Sent from the R help mailing list archive at Nabble.com.
16 days later
Hello Dr. Snow, With regard to your response from earlier this month: 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? I'm still troubled by the fact that layout and subplot (from TeachingDemos) are not playing nicely together on my machine. sessionInfo(): sessionInfo() #R version 2.13.2 (2011-09-30) #Platform: x86_64-pc-mingw32/x64 (64-bit) #other attached packages: #[1] TeachingDemos_2.7 I'd really like to get this working on my machine as it seems to be working on yours. While I previously tried a simply example for the initial forum post, I'm curious if the real plot I'm trying to make works on your machine. Should you happen to have a spare moment and I'm not pushing my luck, I've attached 4 small data files, 1 text file containing the R commands I'm trying to run (including 'layout' and 'subplot' called "R_Commands_Plot_MT3D_Analytical_Comparison_For_Paper.txt"), and the incorrect tiff output I'm getting on my machine. I've directed all paths in the R code to c:/temp/ so everything should quickly work if files are dropped there. Should it work on your machine as we would expect, does anything come to mind for how to fix it on my machine? Very Respectfully, Eric http://r.789695.n4.nabble.com/file/n3926941/AnalyticalDissolvedSorbedConcAt20PoreVols.txt AnalyticalDissolvedSorbedConcAt20PoreVols.txt http://r.789695.n4.nabble.com/file/n3926941/AnalyticalEffluentConcentration.txt AnalyticalEffluentConcentration.txt http://r.789695.n4.nabble.com/file/n3926941/Conc_Breakthru_at_100cm.txt Conc_Breakthru_at_100cm.txt http://r.789695.n4.nabble.com/file/n3926941/Conc_Profile_20T.txt Conc_Profile_20T.txt http://r.789695.n4.nabble.com/file/n3926941/R_Commands_Plot_MT3D_Analytical_Comparison_For_Paper.txt R_Commands_Plot_MT3D_Analytical_Comparison_For_Paper.txt http://r.789695.n4.nabble.com/file/n3926941/NonEquilibrium_ForPaper.tif NonEquilibrium_ForPaper.tif -- View this message in context: http://r.789695.n4.nabble.com/subplot-strange-behavoir-tp3875917p3926941.html Sent from the R help mailing list archive at Nabble.com.
2 days later
I see the problem, I fixed this bug for version 2.8 of TeachingDemos, but have not submitted the new version to CRAN yet (I thought that I had fixed this earlier, but apparently it is still only in the development version). An easy fix is to install version 2.8 from R-forge (install.packages("TeachingDemos", repos="http://R-Forge.R-project.org") and then it should work for you.
Sorry about not seeing this earlier.
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: Friday, October 21, 2011 4:21 PM > To: r-help at r-project.org > Subject: Re: [R] subplot strange behavoir > > Hello Dr. Snow, > > With regard to your response from earlier this month: > > > 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? > > I'm still troubled by the fact that layout and subplot (from > TeachingDemos) > are not playing nicely together on my machine. sessionInfo(): > > sessionInfo() > #R version 2.13.2 (2011-09-30) > #Platform: x86_64-pc-mingw32/x64 (64-bit) > #other attached packages: > #[1] TeachingDemos_2.7 > > I'd really like to get this working on my machine as it seems to be > working > on yours. While I previously tried a simply example for the initial > forum > post, I'm curious if the real plot I'm trying to make works on your > machine. > Should you happen to have a spare moment and I'm not pushing my luck, > I've > attached 4 small data files, 1 text file containing the R commands I'm > trying to run (including 'layout' and 'subplot' called > "R_Commands_Plot_MT3D_Analytical_Comparison_For_Paper.txt"), and the > incorrect tiff output I'm getting on my machine. I've directed all > paths in > the R code to c:/temp/ so everything should quickly work if files are > dropped there. Should it work on your machine as we would expect, does > anything come to mind for how to fix it on my machine? > > Very Respectfully, > Eric > > http://r.789695.n4.nabble.com/file/n3926941/AnalyticalDissolvedSorbedCo > ncAt20PoreVols.txt > AnalyticalDissolvedSorbedConcAt20PoreVols.txt > http://r.789695.n4.nabble.com/file/n3926941/AnalyticalEffluentConcentra > tion.txt > AnalyticalEffluentConcentration.txt > http://r.789695.n4.nabble.com/file/n3926941/Conc_Breakthru_at_100cm.txt > Conc_Breakthru_at_100cm.txt > http://r.789695.n4.nabble.com/file/n3926941/Conc_Profile_20T.txt > Conc_Profile_20T.txt > http://r.789695.n4.nabble.com/file/n3926941/R_Commands_Plot_MT3D_Analyt > ical_Comparison_For_Paper.txt > R_Commands_Plot_MT3D_Analytical_Comparison_For_Paper.txt > http://r.789695.n4.nabble.com/file/n3926941/NonEquilibrium_ForPaper.tif > NonEquilibrium_ForPaper.tif > > -- > View this message in context: http://r.789695.n4.nabble.com/subplot- > strange-behavoir-tp3875917p3926941.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.