# [R] Multiple plots with single box

Greg Snow Greg.Snow at imail.org
Thu Dec 20 22:29:59 CET 2007

```One possibility is to use the cnvrt.coords function from the
TeachingDemos package.  It shows an example of putting a rectangle
across multiple plots.  You would need to create the 1st (top) plot,
find the coordinate of the top and convert that to device coordinates,
then create the rest of your plots and after making the last (bottom)
one find the user coordinates for the left right and bottom, convert the
coordinate for the top from device to current user coordinates and then
plot the rectangle.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
(801) 408-8111

> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Giovanni Petris
> Sent: Tuesday, December 18, 2007 4:22 PM
> To: r-help at r-project.org
> Subject: [R] Multiple plots with single box
>
>
> Hello,
>
> I am trying to display some harmonic functions in a plot. The
> kind of display I have in mind is like the one that cn be
> obtained by a call to plot.ts with plot.type = "multiple".
> The only difference is that I want a single box containing
> all the plots instead of one box per plot. I thought
> box(which = "outer") would have done the job, but it didn't.
>
> Below is the code I have used so far. (R 2.5.1, I know, I know...)
>
> Any help is greatly appreciated.
>
> Giovanni
>
> =================
> ### Plot harmonic functions
> n <- 6 # even
> omega <- 2 * pi / n
>
> par(mfrow = c(n - 1, 1), mar = c(0, 5.1, 0, 5.1), oma = c(3,
> 1, 2, 1)) for (i in 1:(n/2 - 1)) {
>     curve(cos(x * i * omega), 0, n, ylim = c(-1.1, 1.1), ylab
> = "", axes = FALSE)
>     points(1:n, cos(i * omega * 1:n))
>     axis(2); abline(h = 0, col = "lightgrey")
>     curve(sin(x * i * omega), 0, n, ylim = c(-1.1, 1.1), ylab
> = "", axes = FALSE)
>     points(1:n, sin(i * omega * 1:n))
>     axis(4); abline(h = 0, col = "lightgrey") } curve(cos(x *
> (n/2) * omega), 0, n, ylim = c(-1.1, 1.1), ylab = "", axes =
> FALSE) points(1:n, rep(c(-1,1), n/2)) axis(1); axis(2);
> abline(h = 0, col = "lightgrey")
>
> --
>
> Giovanni Petris  <GPetris at uark.edu>
> Department of Mathematical Sciences
> University of Arkansas - Fayetteville, AR 72701
> Ph: (479) 575-6324, 575-8630 (fax)
> http://definetti.uark.edu/~gpetris/
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help