[R] multiple plots in a function()

Gabor Grothendieck ggrothendieck at gmail.com
Tue May 16 05:00:39 CEST 2006


You could override par by optionally passing it as an argument:

f <- function(x = 1:10, y = 1:10, par = list(mfrow = c(2,2))) {
	if (!is.null(par)) {
		on.exit(par(opar))
		opar <- par(par)
	}
	plot(x)
	plot(y)
}

opar <- par(mfrow=c(4,4))
for(i in 1:8) f(par = NULL)
par(opar)



On 5/15/06, Weismann_D at medizin.uni-wuerzburg.de
<Weismann_D at medizin.uni-wuerzburg.de> wrote:
> Dear all,
> I have the following problem:
> I have written a function genereating to plots, eg
> myfunction <- (data, some.parameters) {
>        #some calculations etc
>        .
>        par (mfrow=c(1,2))
>        plot1(......)
>        plot2(.....)
> }
> which works fine. But for analysing several variants, I tried a slope, eg:
>
> par (mfrow=c(5,5))
>  for ( i in 1:10) {
>    myfunction(data, i)
> }
>
> Off course, the par() in myfunction overwrites the par() before the slope. So, how to write myfunction, that it plots two plots and can be used in the slope like in the example?
>
> Thanks a lot, Dirk
>
> Dr.med Dirk Weismann
> Schwerpunkt für Endokrinologie und Diabetologie
> Medizinische Universitätsklinik I
> 97080 Würzburg
> email: weismann_d at klinik.uni-wuerzburg.de
> Telefon: 0049-931-201-36744
>
>        [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>




More information about the R-help mailing list