[R] multiple plots in a function()

Romain Francois francoisromain at free.fr
Sun May 21 11:21:38 CEST 2006


Le 20.05.2006 17:33, Weismann_D at medizin.uni-wuerzburg.de a écrit :
> Sorry for again asking the same question, but I am still not successfull, also after using grid-package, as recommended previously:
>
> I want to write a function() which generates a graphical output and can be used in a loop to produce several results with a layout like in 
>  
> par(mfrow=c(5,5))
> for ( i in 1:10){
> 	plot(1:10)
> } 
>
> Here is the (experimental) code: 
>
>
> myfunction <- function(){
> 	vp1 <- viewport(x=0.1, y=.7, w=.8, h=.2, just="left", name="vp1")
> 	vp2 <- viewport(x=.1, y=.5, w=.8, h=.2, just="left", name="vp2")
> 	pushViewport(vp1)
> 		grid.rect(gp=gpar(col="grey"))
> 		grid.text("vp1")
> 		grid.xaxis(main=FALSE)
> 	upViewport()
> 	pushViewport(vp2)
> 		grid.rect(gp=gpar(col="grey"))
> 		grid.text("vp2")
> 		grid.xaxis()
> }
>
>
> And the following loop:
>
>
> par(mfrow=c(5,5))
> for (i in 1:10) {
> 	 grid.newpage()  # when ommitting this line, the following plots will be plotted as childrens of the afore generated parent
> 	 myfunction()
> }
>
>
> In conclusion, every myfunction() result overwrites the output of the previous output and is not plotted side by side as intended.
>
> What to change?
>
>   
Hi,

RSiteSearch('layout grid')

leads to ?grid.layout


> Thanks a lot, Dirk
>
> Dr.med. D. Weismann
> Schwerpunkt Endokrinologie/Diabetologie
> Medizinische Klinik und Poliklinik I
> Universität Würzburg
> Josef-Schneider-Str. 2
> 97080 Würzburg
> email: weismann_d at klinik.uni-wuerzburg.de
> Telefon: 0931/201-1
>   

-- 
visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
mixmod 1.7 is released : http://www-math.univ-fcomte.fr/mixmod/index.php
+---------------------------------------------------------------+
| Romain FRANCOIS - http://francoisromain.free.fr               |
| Doctorant INRIA Futurs / EDF                                  |
+---------------------------------------------------------------+



More information about the R-help mailing list