example.plot <- function() {
x <- rnorm(100)
y <- rnorm(100)
scale <- range(x, y)
opar <- ExternalLegendLayout(nrow = 2,
ncol = 2,
legend.labels = c("foo", "bar"))
on.exit({par(opar); layout(1)})
hist(x, xlim = scale, axes = FALSE, main = "")
mtext("X", side = 3, line = 1)
box()
plot(x, y, xlim = scale, ylim = scale, axes = FALSE)
box()
axis(3)
axis(4)
plot(y, x, xlim = scale, ylim = scale, axes = FALSE, pch = 2, col = 2)
box()
axis(1)
axis(2)
hist(y, xlim = scale, axes = FALSE, main = "")
mtext("Y", side = 1, line = 1)
box()
AddExternalLegend(legend.labels = c("foo", "bar"),
pch = 1:2,
col = 1:2,
legend.cex = 1.5)
}
## Now call example.plot().
example.plot()
## Because of the call to on.exit(), in example.plot,
## the original plot layout is restored.
hist(1:10)
Run the code above in your browser using DataLab