Skip to content
Prev 138634 / 398506 Next

legend for several graphics

On Wed, 2008-03-05 at 15:28 +0100, Georg Otto wrote:
Here's one way:

op <- par(mfrow = c(3,3), ## split region
          oma = c(5,0,4,0) + 0.1, ## create outer margin
          mar = c(5,4,2,2) + 0.1) ## shrink some margins
plot(1:10, main = "a", pch = 1:2, col= 1:2)
plot(1:10, main = "b", pch = 1:2, col= 1:2)
plot(1:10, main = "c", pch = 1:2, col= 1:2)
plot(1:10, main = "d", pch = 1:2, col= 1:2)
plot(1:10, main = "e", pch = 1:2, col= 1:2)
plot(1:10, main = "f", pch = 1:2, col= 1:2)
plot(1:10, main = "g", pch = 1:2, col= 1:2)
plot(1:10, main = "h", pch = 1:2, col= 1:2)
plot(1:10, main = "i", pch = 1:2, col= 1:2)
## title
mtext("My Plots", side = 3, outer = TRUE, font = 2, line = 1, cex = 1.2)
## draw legend
legend(-12.5, -6, legend = c("Type 1", "Type 2"), pch = 1:2, col = 1:2,
ncol = 2)
par(op)

I had to fiddle by hand with the legend x and y locations to get it
roughly centred. There has to be better way - probably something to do
with reseting the plot region, but I can't recall how to do that now. If
there is, I'm sure someone will tell me what I overlooked.

Is this what you were looking for?

G