Re: [R] multiple plots in a function()

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue 16 May 2006 - 13:00:39 EST

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@medizin.uni-wuerzburg.de <Weismann_D@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@klinik.uni-wuerzburg.de
> Telefon: 0049-931-201-36744
>

> [[alternative HTML version deleted]]
> > >
> ______________________________________________
> R-help@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
>
>

R-help@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 Received on Tue May 16 13:06:23 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 16 May 2006 - 14:10:11 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.