[R] Simple Plot with Grid's Viewport
Gundala Viswanath
gundalav at gmail.com
Thu Mar 19 04:52:51 CET 2009
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
More information about the R-help
mailing list