Dear all, I have the following code that try to plot simple sinus curve into 2x2 grid in 1 page. But this code of mine create 4 plots in 1 page each. What's wrong with my approach? __BEGIN__ library(lattice) library(grid) test.plot <- function(x,y) { pushViewport(viewport(layout.pos.col=x, layout.pos.row=y)) pushViewport(viewport(width=0.6, height=0.6)); plot(sin,-pi,2*pi, main= paste(c(i,j),collapse="-") ) } plotfn <- ("~/Desktop/mygrid.pdf") pdf(plotfn) id = 0; for (i in 1:2) { for (j in 1:2) { id = id+1; cat(i, "-", j, "\n", sep="") test.plot(i,j); } } dev.off() __END__ - Gundala Viswanath
Gundala Viswanath <gundalav <at> gmail.com> writes:> I have the following code that try to plot > simple sinus curve into 2x2 grid in 1 page. > > But this code of mine create 4 plots in 1 page > each. What's wrong with my approach?...> library(lattice) > library(grid) > > test.plot <- function(x,y) { > pushViewport(viewport(layout.pos.col=x, layout.pos.row=y)) > pushViewport(viewport(width=0.6, height=0.6)); > plot(sin,-pi,2*pi, main= paste(c(i,j),collapse="-") ) > > } >... test.plot(i,j); plot (plot.default) is "old-style" graphics and dates before grid. Note that your program would run without error when you remove the library(grid). Use print(xyplot(..)) instead, or use par(...) to generate the layout for your standard plots. Dieter