Skip to content

Multiple plots with single box

2 messages · Giovanni Petris, Greg Snow

#
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. 

Thank you in advance,
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")
1 day later
#
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,