UncertainVagery
UncertainVagery

Reputation: 11

How to specify font sizes in plots with multiple plots per page?

When I generate a .pdf file using knitr from within RStudio, single plots exhibit the desired font sizes of axis labels, legend, etc. However, when I use the layout() function to generate multiple sub-plots, these font sizes are reduced. Please see the example code below.

\documentclass[12pt,english,twocolumn]{article}
\begin{document}
<<settings, message=FALSE, echo=FALSE, cache=FALSE>>=
# set tikz default options
opts_chunk$set(
  out.width='15cm',
  fig.width=5.906, # inch
  fig.height=5.906, # inch
  dev='tikz',
  fig.align='center',
  fig.lp='fig:',
  fig.env='figure*',
  dev.args=list(pointsize=10),
  message=FALSE, 
  echo=FALSE
)
options(tikzDefaultEngine = "pdftex")
@
<<singlePlot, fig.cap="single plot with good font size">>=
par(cex=1)
plot(rnorm(100))
@
<<multiplePlots, fig.cap="multiple plots with fonts being too small">>=
par(cex=1)
layout(matrix(1:9, 3))
for(i in 1:9) plot(rnorm(100))
@
\end{document}

How do I get fonts in the second plot to be of the same size as the ones in the first plot? Thanks!

Upvotes: 0

Views: 165

Answers (1)

UncertainVagery
UncertainVagery

Reputation: 11

Oh my, I figured it out by myself just 30 seconds after posting the question...

The trick is to reverse the order of layout() and par() in the second plot, like so:

<<multiplePlots, fig.cap="multiple plots with fonts being just right">>=
layout(matrix(1:9, 3))
par(cex=1)
for(i in 1:9) plot(rnorm(100))
@

This works as expected.

So it seems that layout() calls par() internally to set a new (smaller) character expansion value when setting up multiple plots. Thus setting par(cex=1) before layout had no effect. I had not known this, but it makes sense. Sorry for the unneccessary disturbance.

Upvotes: 1

Related Questions