Hesen Peng-2 wrote: > > I created a plot function which used par(mfcol=c(2,1)) so that I could > have two plots together using just one command. > > For exampe: > > plot.foo <- function(data){ > par(mfcol=c(2,1)) > hist(data) > plot(data) > } > > Later I wanted to show 4 of these foo objects in the same picture. So > I used par(mfcol=c(2,2)) again at the beginning of the code like: > > par(mfcol=c(2,2)) > plot(foo.1) > plot(foo.2) > plot(foo.3) > plot(foo.4) > > but this time the par() command inside of the functions seem to be > overwriting the par() command at the very begining. Can anyone please > give me some advise on dealing with this? I guess that I may either > need to change the way I plot foo, e.g. using some function rather > than par(), or use some parameters at the beginning. Thank you very > much, >
Your example starts fine, but does not run because is it unclear what foo.1 etc. means. Please really post complete examples, chances are higher you get a reasonable answer. Reading between the lines, I suspect that you mixed up the concepts of trellis plots with those of standard plot(). I think you believed that your function returns the plot object, which is approximately true for trellis where you could use a list of graphics objects and print() or plot() these later in a given arrangement with split(). As an easy solution with standard graphics, I suggest the not-so-elegant one below. You should probably adjust the margins a bit to make clear that graphs are pairs. Dieter data = rnorm(100) plot.foo <- function(data){ # par(mfcol=c(2,1)) hist(data) plot(data) } par(mfcol=c(4,2)) plot.foo(data) plot.foo(data) # Use other data here plot.foo(data) plot.foo(data) -- View this message in context: http://www.nabble.com/Multiple-use-of-par%28%29-tp22876693p22881832.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.