Add Title for a Page with Multiple Plots in R

You may want to add a title for a plot page that contains multiple diagrams. The following R code plot 3 diagrams on one page, and add a title to the page.

# create a simple data frame
a <- c(1,2,3,4,5)
b <- c(1,2,3,4,4)
df <-data.frame(a,b)

# plot 3 lines
pdf("plot.pdf", width=8,height=11)
par(mfrow=c(2,2),mar=c(4,4,0.5,0.5), oma=c(1.5,2,1,1))
plot(df$a,df$b, type="l")
plot(df$a,df$b, type="l")
plot(df$a,df$b, type="l")

# add title for the page
mtext("Three Diagrams in One Page", outer=TRUE,  cex=1, line=-0.5)

In the code above, cex controls the font size. The default value is 1. You can check out the documentation for cex.

The generated pdf files looks like the following:

Category >> R  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";