How to set page title font size in R?

How to set page title font size is not clear in R’s documentation. It can take a lot of time to figure out how to set font size. The following code shows how to change font size.

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

# set up generated file name and page size. 
pdf("plot.pdf", width=8,height=11)

# set number of diagrams on one page
par(mfrow=c(2,2),mar=c(4,4,0.5,0.5), oma=c(1.5,2,1,1))

# plot 3 lines
plot(df$a,df$b, type="l")
plot(df$a,df$b, type="l")
plot(df$a,df$b, type="l")

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

dev.off()

The font size of title can be configured by using the cex parameter of the mtext() method.

cex parameter controls the font size. The default value is 1. See the documentation for more details.

Leave a Comment