Re: [R] Simple Plot with Grid's Viewport

2009-03-19 Thread Dieter Menne
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

__
R-help@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.


Re: [R] Simple Plot with Grid's Viewport

2009-03-19 Thread baptiste auguie


On 19 Mar 2009, at 07:22, Dieter Menne wrote:


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



Alternatively, you can

- use grid.points or a similar grid function to create the plot, as  
described in Paul Murrell's tutorial,

 http://www.stat.auckland.ac.nz/~paul/grid/doc/plotexample.pdf

- use ggplot2 instead of plot

- use gridBase to mix base graphics and grid graphics

- use split.screen in combination with base graphics


baptiste


__
R-help@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.


_

Baptiste AuguiƩ

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
R-help@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.