I would like to know how to provide a common title and legend for combined plots in R. I have four plots which I have combined into one. Each plot has its own Title. I want to specify a common Title on the top center and common legend on the top left corner of the combined plot. I generated the combined plot using par(). I have provided my plot below
Asked
Active
Viewed 1.8k times
20

user3897
- 551
- 2
- 5
- 14
1 Answers
22
You can use the oma
parameter to increase the outer margins,
then add the main title with mtext
,
and try to position the legend by hand.
op <- par(
oma=c(0,0,3,0),# Room for the title and legend
mfrow=c(2,2)
)
for(i in 1:4) {
plot( cumsum(rnorm(100)), type="l", lwd=3,
col=c("navy","orange")[ 1+i%%2 ],
las=1, ylab="Value",
main=paste("Random data", i) )
}
par(op) # Leave the last plot
mtext("Main title", line=2, font=2, cex=1.2)
op <- par(usr=c(0,1,0,1), # Reset the coordinates
xpd=NA) # Allow plotting outside the plot region
legend(-.1,1.15, # Find suitable coordinates by trial and error
c("one", "two"), lty=1, lwd=3, col=c("navy", "orange"), box.col=NA)

Vincent Zoonekynd
- 31,893
- 5
- 69
- 78
-
2Welcome, Vincent! Your webpages were very useful to me in my early stages of learning R. Nice illustration of managing margins. – IRTFM Jan 05 '12 at 05:51
-
how do I put the "Main title" at the bottom? – d.putto Mar 17 '15 at 12:23