Hi! I am troubled by Sweave which I want to use in order to plot graphics which I build up successively by the use of grid.layout. Here is the code: <<fig=TRUE,label=evolDist,height=6in,width=3in,pdf=FALSE>> ## combined plot via grid viewports grid.newpage() pushViewport(viewport(layout=grid.layout(2,1))) vlay <- function(x,y) viewport(layout.pos.row=x, layout.pos.col=y) print(pl$gscoreDist, vp=vlay(1,1)) print(pl$acceptDist, vp=vlay(2,1)) dev.off() @ The error is the following from Sweave: Error in grid.newpage() : Non-finite location and/or size for viewport In addition: There were 24 warnings (use warnings() to see them) Error in driver$runcode(drobj, chunk, chunkopts) : Error in grid.newpage() : Non-finite location and/or size for viewport Calls: Sweave -> <Anonymous> Execution halted Any hints? Of course, I can always wrap the code into a fig=FALSE, and pdf()-call, but that is not how sweave is meant to be used, as I got it. Many thanks in advance, Sebastian Weber [[alternative HTML version deleted]]
I just run the code below with sweave and works fine It looks like you might be missing the sequence of vplay <<fig.R,echo=F,fig=T>>library(ggplot2) vplay<- function(x, y) viewport(layout.pos.row=x, layout.pos.col=y) grid.newpage() p <- ggplot(diamonds, aes(x=carat, y=..density..)) + geom_histogram(binwidth=0.2) p <- p + facet_grid(. ~ cut) pushViewport(viewport(layout=grid.layout(3,3))) print(p, vp=vplay(1,1)) print(p, vp=vplayt(2:3,2:3)) print(p, vp=vplay(1, 2:3)) print(p, vp=vplay(2:3, 1)) @ ? Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA ----- Original Message ----> From: Sebastian Weber <sebastian.weber at physik.tu-darmstadt.de> > To: r-help at r-project.org > Sent: Mon, July 26, 2010 7:51:06 AM > Subject: [R] Trouble using grid.layout in Sweave > > Hi! > > I am troubled by Sweave which I want to use in order to plot graphics which > I build up successively by the use of grid.layout. Here is the code: > > <<fig=TRUE,label=evolDist,height=6in,width=3in,pdf=FALSE>>> > ## combined plot via grid viewports > grid.newpage() > pushViewport(viewport(layout=grid.layout(2,1))) > vlay <- function(x,y) viewport(layout.pos.row=x, layout.pos.col=y) > print(pl$gscoreDist, vp=vlay(1,1)) > print(pl$acceptDist, vp=vlay(2,1)) > dev.off() > > @ > > The error is the following from Sweave: > > Error in grid.newpage() : Non-finite location and/or size for viewport > In addition: There were 24 warnings (use warnings() to see them) > Error in driver$runcode(drobj, chunk, chunkopts) : > ? Error in grid.newpage() : Non-finite location and/or size for viewport > Calls: Sweave -> <Anonymous> > Execution halted > > > Any hints? Of course, I can always wrap the code into a fig=FALSE, and > pdf()-call, but that is not how sweave is meant to be used, as I got it. > > Many thanks in advance, > > Sebastian Weber > > ??? [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
Hi On 27/07/2010 2:51 a.m., Sebastian Weber wrote:> Hi! > > I am troubled by Sweave which I want to use in order to plot graphics which > I build up successively by the use of grid.layout. Here is the code: > > <<fig=TRUE,label=evolDist,height=6in,width=3in,pdf=FALSE>>Is the problem just that you have specified "height=6in" rather than "height=6" ? i.e., does ... <<fig=TRUE,label=evolDist,height=6,width=3,pdf=FALSE>> ... work better for you ? Paul> ## combined plot via grid viewports > grid.newpage() > pushViewport(viewport(layout=grid.layout(2,1))) > vlay<- function(x,y) viewport(layout.pos.row=x, layout.pos.col=y) > print(pl$gscoreDist, vp=vlay(1,1)) > print(pl$acceptDist, vp=vlay(2,1)) > dev.off() > > @ > > The error is the following from Sweave: > > Error in grid.newpage() : Non-finite location and/or size for viewport > In addition: There were 24 warnings (use warnings() to see them) > Error in driver$runcode(drobj, chunk, chunkopts) : > Error in grid.newpage() : Non-finite location and/or size for viewport > Calls: Sweave -> <Anonymous> > Execution halted > > > Any hints? Of course, I can always wrap the code into a fig=FALSE, and > pdf()-call, but that is not how sweave is meant to be used, as I got it. > > Many thanks in advance, > > Sebastian Weber > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.-- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/