4

I would like to assemble the following four pictures in a 2x2 matrix (filling rows first):

enter image description here

enter image description here enter image description here enter image description here

Is there a possibility to put the letters A-D at the bottom left of each figure to label them? Thank you! I am learning Latex graphics. If I can save it as a pdf, then I can easily use "figure" to create my final image with caption.

Picture 1:

    \documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{width=10cm,compat=1.9}
\usepackage{filecontents}
\begin{filecontents*}{all_men.csv}
a,b
1.431363764,0.880475418
1.505149978,0.984842271
1.568201724,1.182782759
1.62324929,1.426034556
1.672097858,1.764098403
1.716003344,2.109656911
1.755874856,2.37117351
1.792391689,2.609995129
1.826074803,2.827907138
1.857332496,3.008590765
\end{filecontents*}

\begin{filecontents*}{steps_men.csv}
a,b
1.431363764,0.880475418
1.431363764,0.984842271
1.505149978,0.984842271
1.505149978,1.182782759
1.568201724,1.182782759
1.568201724,1.426034556
1.62324929,1.426034556
1.62324929,1.764098403
1.672097858,1.764098403
1.672097858,2.109656911
1.716003344,2.109656911
1.716003344,2.37117351
1.755874856,2.37117351
1.755874856,2.609995129
1.792391689,2.609995129
1.792391689,2.827907138
1.826074803,2.827907138
1.826074803,3.008590765
1.857332496,3.008590765
\end{filecontents*}

\begin{document}
\pgfplotstableread[col sep=comma]{steps_men.csv}\datatable
\begin{tikzpicture}
\begin{axis}[
    title={Men},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={0.880475418,0.984842271,1.182782759,1.426034556,1.764098403,2.109656911,
    2.37117351,2.609995129,2.827907138,3.008590765},
    yticklabels={8,10,15,27,58,129,235,407,673,1020},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\datatable};
\pgfplotstableread[col sep=comma]{all_men.csv}\datatable
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\datatable};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x 
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
\end{axis}
\end{tikzpicture}
\hspace{0.10cm}
\end{document}

Picture 2:

\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{width=10cm,compat=1.9}
\usepackage{filecontents}
\begin{filecontents*}{all_women.csv}
a,b
1.431363764,0.769618098
1.505149978,1.001975048
1.568201724,1.321239024
1.62324929,1.599722199
1.672097858,1.874640705
1.716003344,2.13993154
1.755874856,2.338819817
1.792391689,2.520699054
1.826074803,2.692504537
1.857332496,2.851417046
\end{filecontents*}

\begin{filecontents*}{steps_women.csv}
a,b
1.431363764,0.769618098
1.431363764,1.001975048
1.505149978,1.001975048
1.505149978,1.321239024
1.568201724,1.321239024
1.568201724,1.599722199
1.62324929,1.599722199
1.62324929,1.874640705
1.672097858,1.874640705
1.672097858,2.13993154
1.716003344,2.13993154
1.716003344,2.338819817
1.755874856,2.338819817
1.755874856,2.520699054
1.792391689,2.520699054
1.792391689,2.692504537
1.826074803,2.692504537
1.826074803,2.851417046
1.857332496,2.851417046
\end{filecontents*}

\begin{document}
\pgfplotstableread[col sep=comma]{steps_women.csv}\datatable
\begin{tikzpicture}
\begin{axis}[
    title={Women},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={0.769618098,1.001975048,1.321239024,1.599722199,1.874640705,2.13993154,2.338819817,2.520699054,
    2.692504537,2.851417046},
    yticklabels={6,10,21,40,75,138,218,332,493,710},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\datatable};
\pgfplotstableread[col sep=comma]{all_women.csv}\datatable
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\datatable};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x 
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
\end{axis}
\end{tikzpicture}
\hspace{0.10cm}
\end{document}

Picture 3:

\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{width=10cm,compat=1.9}
\usepackage{filecontents}
\begin{filecontents*}{all_women.csv}
a,b
1.431363764,-0.114988484
1.505149978,0.303005044
1.568201724,0.806163983
1.62324929,1.109635968
1.672097858,1.24886644
1.716003344,1.50350828
1.755874856,1.621079988
1.792391689,1.714388602
1.826074803,1.830499259
1.857332496,1.888497767
\end{filecontents*}

\begin{filecontents*}{select_women.csv}
a,b
1.431363764,-0.114988484
1.505149978,0.303005044
1.568201724,0.806163983
1.62324929,1.109635968
\end{filecontents*}

\begin{filecontents*}{steps_women.csv}
a,b
1.431363764,-0.114988484
1.431363764,0.303005044
1.505149978,0.303005044
1.505149978,0.806163983
1.568201724,0.806163983
1.568201724,1.109635968
1.62324929,1.109635968
1.62324929,1.24886644
1.672097858,1.24886644
1.672097858,1.50350828
1.716003344,1.50350828
1.716003344,1.621079988
1.755874856,1.621079988
1.755874856,1.714388602
1.792391689,1.714388602
1.792391689,1.830499259
1.826074803,1.830499259
1.826074803,1.888497767
1.857332496,1.888497767
\end{filecontents*}

\begin{document}
\pgfplotstableread[col sep=comma]{steps_women.csv}\datatable
\begin{tikzpicture}
\begin{axis}[
    title={Breast},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={-0.114988484,0.303005044,0.806163983,1.109635968,1.24886644,1.50350828,1.621079988,1.714388602,1.830499259,1.888497767},
    yticklabels={1,2,6,13,18,32,42,52,68,77},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\datatable};
\pgfplotstableread[col sep=comma]{select_women.csv}\datatable
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\datatable};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x 
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
\end{axis}
\end{tikzpicture}
\hspace{0.10cm}
\end{document}

Picture 4:

\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{width=10cm,compat=1.9}
\usepackage{filecontents}
\begin{filecontents*}{all_women.csv}
a,b
1.431363764,-0.467171002
1.505149978,-0.456662801
1.568201724,0.056784475
1.62324929,0.200868848
1.672097858,0.652092045
1.716003344,0.906600123
1.755874856,1.095174788
1.792391689,1.32472112
1.826074803,1.427429728
1.857332496,1.6849476
\end{filecontents*}

\begin{filecontents*}{steps_women.csv}
a,b
1.431363764,-0.467171002
1.431363764,-0.456662801
1.505149978,-0.456662801
1.505149978,0.056784475
1.568201724,0.056784475
1.568201724,0.200868848
1.62324929,0.200868848
1.62324929,0.652092045
1.672097858,0.652092045
1.672097858,0.906600123
1.716003344,0.906600123
1.716003344,1.095174788
1.755874856,1.095174788
1.755874856,1.32472112
1.792391689,1.32472112
1.792391689,1.427429728
1.826074803,1.427429728
1.826074803,1.6849476
1.857332496,1.6849476
\end{filecontents*}

\begin{document}
\pgfplotstableread[col sep=comma]{steps_women.csv}\datatable
\begin{tikzpicture}
\begin{axis}[
    title={Colon (Women)},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={-0.467171002,0.056784475,0.200868848,0.652092045,0.906600123,1.095174788,1.32472112,1.427429728,1.6849476},
    yticklabels={0,1,2,4,8,12,21,27,48},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\datatable};
\pgfplotstableread[col sep=comma]{all_women.csv}\datatable
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\datatable};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x 
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
\end{axis}
\end{tikzpicture}
\hspace{0.10cm}
\end{document}

EDIT:

\documentclass[12pt,a4paper,twoside]{report}
\usepackage{graphicx}
\usepackage{caption,subcaption}
\usepackage[margin=0.5in]{geometry}

\begin{document}
  \begin{figure}[htb]
  \captionsetup[subfigure]{singlelinecheck=off,labelfont={bf}}
  \renewcommand\thesubfigure{\Alph{subfigure}}
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{Figure2a}
      \caption{}
    \end{subfigure}%
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{Figure2b}
      \caption{}
    \end{subfigure}

    \vspace{1cm}
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{Figure2c}
      \caption{}
    \end{subfigure}%
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{Figure2d}
      \caption{}
    \end{subfigure}
  \end{figure}
\end{document}

Which gives:

enter image description here

Is there a possibility to align the letters under the "Rates per 100 000"?

1
  • @HarishKumar Hi Harish! I posted the code for the pictures, I will look into groupplots :)
    – Johnathan
    Commented Apr 13, 2015 at 4:43

1 Answer 1

5

There are two ways atleast for doing this. First using subcaption and its subfigure environment and two using groupplots library of pgfplots. First using grouplots:

\documentclass[border=5]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{width=10cm,compat=1.9}
\usepgfplotslibrary{groupplots}


\begin{document}
\pgfplotstableread[col sep=comma]{steps_men.csv}\men
\pgfplotstableread[col sep=comma]{steps_women.csv}\women
\pgfplotstableread[col sep=comma]{all_men.csv}\menall
\pgfplotstableread[col sep=comma]{all_women.csv}\womenall
\pgfplotstableread[col sep=comma]{select_women.csv}\selectwomen
\begin{tikzpicture}
\begin{groupplot}[
            group style={
                group name=my plots,
                group size=2 by 2,
                vertical sep=3cm,
                horizontal sep=3cm,
            },
            width=\linewidth,
        ]
\nextgroupplot[
    title={Men},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={0.880475418,0.984842271,1.182782759,1.426034556,1.764098403,2.109656911,
    2.37117351,2.609995129,2.827907138,3.008590765},
    yticklabels={8,10,15,27,58,129,235,407,673,1020},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\men};
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\menall};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
%
\nextgroupplot[
    title={Women},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={0.769618098,1.001975048,1.321239024,1.599722199,1.874640705,2.13993154,2.338819817,2.520699054,
    2.692504537,2.851417046},
    yticklabels={6,10,21,40,75,138,218,332,493,710},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\women};
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\womenall};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}

\nextgroupplot[
    title={Breast},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={-0.114988484,0.303005044,0.806163983,1.109635968,1.24886644,1.50350828,1.621079988,1.714388602,1.830499259,1.888497767},
    yticklabels={1,2,6,13,18,32,42,52,68,77},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\women};
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\selectwomen};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
%
\nextgroupplot[
    title={Colon (Women)},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={-0.467171002,0.056784475,0.200868848,0.652092045,0.906600123,1.095174788,1.32472112,1.427429728,1.6849476},
    yticklabels={0,1,2,4,8,12,21,27,48},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\women};
\pgfplotstableread[col sep=comma]{all_women.csv}\womenall
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\womenall};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
\end{groupplot}
%% add labels using tikz.
\node[font=\bfseries,scale=3] at ([shift={(-1.5cm,-1.1cm)}]my plots c1r1.south west) {A.};
\node[font=\bfseries,scale=3] at ([shift={(-1.5cm,-1.1cm)}]my plots c2r1.south west) {B.};
\node[font=\bfseries,scale=3] at ([shift={(-1.5cm,-1.1cm)}]my plots c1r2.south west) {C.};
\node[font=\bfseries,scale=3] at ([shift={(-1.5cm,-1.1cm)}]my plots c2r2.south west) {D.};
\end{tikzpicture}
\end{document}

enter image description here

Use your data as mine is very raw and hence graphs are not what you want.

With subfigure from subcaption it looks like this:

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption,subcaption}

\begin{document}
  \begin{figure}[htb]
  \captionsetup[subfigure]{singlelinecheck=off,labelfont={bf,Large}}
  \renewcommand\thesubfigure{\Alph{subfigure}}
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{example-image-a}
      \caption{}
    \end{subfigure}%
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{example-image-b}
      \caption{}
    \end{subfigure}

    \vspace{1cm}
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{example-image-c}
      \caption{}
    \end{subfigure}%
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{example-image}
      \caption{}
    \end{subfigure}
  \end{figure}
\end{document}

enter image description here

2
  • Thank you! I have added the grid. Is there a possibility to align the letters under the "Rates per 100 000"?
    – Johnathan
    Commented Apr 13, 2015 at 15:49
  • @Johnathan Yes but only tomorrow. :-)
    – user11232
    Commented Apr 13, 2015 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .