# How to insert many tikzpicture R plot images as .tex files inside a table of images in LaTeX?

I can include my R plots in a LaTeX document using tikz package (on the LaTeX side) and tikzDevice package on the R side. I produced many .tex files containing my plots in R using as an example the following code in R:

library(tikzDevice)
tikz(file = 'BarplotScreenType.tex', width = 3, height = 3)
barplot(height=table(screentype),main="", xlab="Types of screens",  ylab="Count", ylim=c(0,12),  col="blue")
dev.off()


What I need to do is to include all these .tex files in a nice border-less table of images in the LaTeX document. I previously used a piece of code (shown below) that allowed me to put png images using \raisebox{-.1\height}{\includegraphics[width=0.5\textwidth, height=0.3\textheight, inner]{AchavanichOriginalCROPED1}}:

\begin{table*}[!htbp]
\caption{Table showing decimated images of Achavanich Beaker(original
resolution was 6.1M faces - 1st picture on left)}\label{table:images}
\centering
\begin{center}
\begin{tabular}{p{8.9cm}p{8.2cm}}
\raisebox{-.1\height}{\includegraphics[width=0.5\textwidth,
height=0.3\textheight, inner]
{AchavanichOriginalCROPED1}}&\raisebox{-.1\height}
{\includegraphics[width=0.5\textwidth, height=0.3\textheight, inner]
{Achavanich3MCROPED3}} \\
\raisebox{-.1\height}{\includegraphics[width=0.5\textwidth,
height=0.3\textheight, inner]

{Achavanich15MCROPED2}}&\raisebox{-.1\height}
{\includegraphics[width=0.5\textwidth,

height=0.3\textheight, inner]{Achavanich750KCROPED2}} \\
\raisebox{-.1\height}{\includegraphics

[width=0.5\textwidth, height=0.3\textheight, inner]
{Achavanich300KCROPED}}&\raisebox

{-.1\height}{\includegraphics[width=0.5\textwidth, height=0.3\textheight,
inner]

{Achavanich100KCROPED}} \\
\end{tabular}
\end{center}
\end{table*}


\includegraphics does not support .tex as an extension even .tex files contain a blocks of \tikzpicture commands.

Another important thing: I need a caption for each figure and a label (for cross referencing...).

Any ideas of how that might be done? Any better suggestions would also be greatly appreciated!

Use \input instead of \includegraphics. Do not forget to set the proper width and height of your graphic chunks

Example:

tikz(file="cars.tex", width=2, height=2)
par(mar=c(2,2,0.5,0.5))
plot(cars, xlab="", ylab="")
dev.off()

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tabular}{ll}
\input{cars} & \input{cars}\\
\input{cars} & \input{cars}
\end{tabular}
\end{document}
`

• Boris Kindly, how do I put a caption and label so I can reference it from LaTeX side? Do you know? If I put the "\include{}" like the following " \begin{figure} \include{graph1} \caption{M1} \label{fig:M1} \end{figure}", I receive an error.
– HB87
Mar 20 '17 at 15:08
• Sorry, I figured out the solution. Using the package \usepackage{subcaption} and inside the table I can then put the following form: \begin{subfigure}{0.4\textwidth}\centering \include{barplotGraph} \caption{Figure A: Graph 1} \label{fig:taba} \end{subfigure}
– HB87
Mar 20 '17 at 15:21
• Great. There are several ways to do this; this is a good one. Mar 20 '17 at 17:21