1

I'd like to input four subfigures (2 x 2) using the figure extension .tex. In my MWE I could not put the figures as subfigures. MWE:

R Input

tikz('test.tex', width = 3.543312, height = 3.543312)
plot(x = runif(10), y = 2*runif(10))
dev.off()

tikz('test1.tex', width = 3.543312, height = 3.543312)
    plot(x = runif(10), y = 2*runif(10))
dev.off()

tikz('test2.tex', width = 3.543312, height = 3.543312)
    plot(x = runif(10), y = 2*runif(10))
dev.off()

tikz('test3.tex', width = 3.543312, height = 3.543312)
    plot(x = runif(10), y = 2*runif(10))
dev.off()

R Output for one figure

% Created by tikzDevice version 0.10.1 on 2018-03-03 14:05:26
% !TEX encoding = UTF-8 Unicode
\begin{tikzpicture}[x=1pt,y=1pt]
\definecolor{fillColor}{RGB}{255,255,255}
\path[use as bounding box,fill=fillColor,fill opacity=0.00] (0,0) rectangle (256.08,256.08);
\begin{scope}
\path[clip] ( 49.20, 61.20) rectangle (230.88,206.88);
\definecolor{drawColor}{RGB}{0,0,0}

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 71.52,174.13) circle (  2.25);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 55.93,122.44) circle (  2.25);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 93.37,101.99) circle (  2.25);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (120.02,201.15) circle (  2.25);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 91.43,185.80) circle (  2.25);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (224.15,154.88) circle (  2.25);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 80.97, 66.60) circle (  2.25);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 98.43,201.48) circle (  2.25);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 95.13,138.22) circle (  2.25);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (199.15,109.17) circle (  2.25);
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (256.08,256.08);
\definecolor{drawColor}{RGB}{0,0,0}

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 50.02, 61.20) -- (204.08, 61.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 50.02, 61.20) -- ( 50.02, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 88.54, 61.20) -- ( 88.54, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (127.05, 61.20) -- (127.05, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (165.57, 61.20) -- (165.57, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (204.08, 61.20) -- (204.08, 55.20);

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 50.02, 39.60) {0.0};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 88.54, 39.60) {0.2};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (127.05, 39.60) {0.4};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (165.57, 39.60) {0.6};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (204.08, 39.60) {0.8};

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20, 65.61) -- ( 49.20,205.47);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20, 65.61) -- ( 43.20, 65.61);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,100.58) -- ( 43.20,100.58);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,135.54) -- ( 43.20,135.54);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,170.50) -- ( 43.20,170.50);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,205.47) -- ( 43.20,205.47);

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80, 65.61) {0.0};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,100.58) {0.5};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,135.54) {1.0};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,170.50) {1.5};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,205.47) {2.0};

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20, 61.20) --
    (230.88, 61.20) --
    (230.88,206.88) --
    ( 49.20,206.88) --
    ( 49.20, 61.20);
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (256.08,256.08);
\definecolor{drawColor}{RGB}{0,0,0}

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (140.04, 15.60) {runif(10)};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 10.80,134.04) {2 * runif(10)};
\end{scope}
\end{tikzpicture}

In Latex

\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{lineno,hyperref}

\usepackage{setspace}
\usepackage{multirow}
\usepackage{array}

\usepackage{graphics}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage[subrefformat=parens,labelformat=parens]{subfig}


\begin{document}

\lipsum[1]

\onecolumn
\begin{figure}[ht]
    \centering
    \setlength{\abovecaptionskip}{-35pt} 
    \caption{Testando Figuras}
    \input{test.tex}
    \input{test1.tex}
    %
    \input{test2.tex}
    \input{test3.tex}
\end{figure}

\twocolumn
\lipsum[1]


\end{document}
  • 1
    When you say that you 'could not', why not? What happens? Probably you need to put them into boxes or minipages. If you want them to be sub-figures, you should use the facilities provided by subfig or, preferably, by subcaption. Your current code does not appear to attempt to typeset them as sub-figures at all, so it isn't altogether clear what you're doing. – cfr Mar 3 '18 at 18:25
  • It will be easier for people to reproduce if you supply the content of the .tex files you want to use, rather than the R code you use to produce them. – cfr Mar 3 '18 at 18:26
  • 1
    I put the R output, the archives test1.tex, test2.tex and test3.tex can be copy of test.tex. – Wagner Jorge Mar 3 '18 at 18:37
  • 1
    Thanks. Equivalently, we can just use the same .tex file four times .... ;). – cfr Mar 3 '18 at 18:41
  • In what sense doesn't it work for you? I get all four plots in a figure. Of course, my plots are identical as I just fed the file in 4 times, but they are arranged 2x2. – cfr Mar 3 '18 at 18:56
1
  • your question is not clear ... i guess similarly as cfr that each image should be inserted in subfloat environment
  • change from two columns to one column before image and back after image cause that image is on separate page. however i would rather that figure float in text. therefore i would use figure* environment. that it can appear on the same page, where is inserted (if there is enough space for image) i would load also stfloats package in document preamble
  • off topic, but can be important: code for your image is very unnecessary complicated. use of pgfplots package can very simplify its code. for example:

    \begin{tikzpicture}[x=1pt,y=1pt]
\begin{axis}[
    xmin=0, xmax=250,
    ymin=0, ymax=250,
    xlabel={runif(10)},
    ylabel={2*runif(10)},
    xticklabels={,0,0.2,0.4,0.5,0.8,1},
    yticklabels={,0,0.5,1.0,1.5,2.0,2.5}
            ]
\addplot [only marks, mark=o] coordinates {
    ( 71.52,174.13) (55.93,122.44)  (93.37,101.99)  (120.02,201.15) ( 91.43,185.80)
    (224.15,154.88) (80.97, 66.60)  (98.43,201.48)  ( 95.13,138.22) (199.15,109.17)
                                            };
\end{axis}
    \end{tikzpicture}

(even simpler can become, if you convert marks coordinates to cm)

with use of stfloats package and figure* environment you can obtain:

enter image description here

complete mwe:

\documentclass[journal,compsoc]{IEEEtran}
\usepackage{lineno}
\usepackage{setspace}
\usepackage{stfloats} % for positioning of figure* on the same page
\usepackage{array, multirow}
\usepackage{pgfplots}% loads tikz, which load graphicx, which loads graphics
\pgfplotsset{compat=1.15,
             height=0.8\columnwidth,
             width=\columnwidth
             }
\usepackage[subrefformat=parens,labelformat=parens,caption=false]{subfig}
\usepackage{hyperref}% should be loaded last

\usepackage{lipsum}

\begin{document}

\lipsum[1]

\begin{figure*}[b]
    \caption{Testando Figuras}
    \subfloat[sub-caption]{%
      \input{job11}}
    \hfill
    \subfloat[sub-caption]{%
      \input{job11}}

    \subfloat[sub-caption]{%
      \input{job11}}
    \hfill
    \subfloat[sub-caption]{%
      \input{job11}}
\end{figure*}
\lipsum
\end{document}
2

sub-figures

\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{lineno}
\usepackage{setspace}
\usepackage{multirow}
\usepackage{array}
\usepackage{tikz}% loads graphicx, which loads graphics
\usepackage{lipsum}
\usepackage[subrefformat=parens,labelformat=parens,caption=false]{subfig}% p. 47 of subfig manual re. IEEEtran class usage
\usepackage{hyperref}% should be loaded last

\begin{document}

\lipsum[1]

\onecolumn
\begin{figure}[ht]
    \centering
    \setlength{\abovecaptionskip}{-35pt} 
    \caption{Testando Figuras}
    \subfloat[sub-caption]{%
      \input{\jobname-1}}
    \subfloat[sub-caption]{%
      \input{\jobname-1}}

    \subfloat[sub-caption]{%
      \input{\jobname-1}}
    \subfloat[sub-caption]{%
      \input{\jobname-1}}
\end{figure}

\twocolumn
\lipsum[1]


\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.