How do I tile plots from a ggplot on a page using r/sweave/latex

39 views Asked by At

I am using R/Sweave/Latex to create an article with ggplot plots in it. I would like to tile 4 plots on one page and I'm wondering what the best way is to go about it? code for one of my plots is below but even with one plot, I am having problems resizing it and aligning it

Thanks

\begin{figure}
\centering{}
<<echo=FALSE,fig=TRUE, width = 10>>=
DisPlot
@
  \vspace*{-35mm}
  \caption{Test caption}
\label{fig:Test}
\end{figure}
1

There are 1 answers

0
rEbbasta On

use par() to tile your plots in a grid. Use \setkeys{Gin} to change size inside the page. Here a working example

<<echo = FALSE>>==
x <- c(1,2,3)
y <- c(4,5,6)
@

\documentclass{article}
\usepackage{tcolorbox}
\begin{document}
\SweaveOpts{concordance=TRUE}

\setkeys{Gin}{width=1.0\textwidth,keepaspectratio}
\begin{figure}
<<fig = TRUE, echo = FALSE >>==
par(mfrow = c(2,2))
plot(x,y)
plot(x,y)
plot(x,y)
plot(x,y)
@
\end{figure}

\end{document}