[R] Simple Plot with Grid's Viewport

Dieter Menne dieter.menne at menne-biomed.de
Thu Mar 19 08:22:58 CET 2009


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




More information about the R-help mailing list