[Tex/LaTex] Plot alignment using groupplot in pgfplots

groupplotspgfplotstikz-pgf

I am using the groupplots library in pgfplots to create plot groupings. I am using the 2×2 sizing but only have 3 plots. How can I center the furthest right plot vertically, to make a triangle rather than an upside down L? In another case, I would like to center the bottom plot horizontally, would this use the same procedure? Is there a better tool to use than groupplots?

\documentclass{standalone}
\usepackage{tikz,pgfplots}
    \usepgfplotslibrary{groupplots}

\begin{document}
  \begin{tikzpicture}
    \begin{groupplot}[
      group style={group size=2 by 2},
      width=4cm, height=4cm,
    ]
    \nextgroupplot
      \addplot coordinates{(0,0) (1,2) (2,1)};
    \nextgroupplot
      \addplot coordinates{(0,0) (1,2) (2,1)};
    \nextgroupplot
      \addplot coordinates{(0,0) (1,2) (2,1)};
    \end{groupplot}
  \end{tikzpicture}
\end{document}

Best Answer

Thanks to Jake's suggestion, a significant compression of my original solution is possible (since I don't know a thing about tikz). Also, a new version of stackengine should hit the streets this weekend. The syntax I used here will work in both old and new versions. You can control the inter-plot separation, if desired (i.e., normal hspacing will work between the top two plots, and an optional length argument to \stackunder will define the vertical gap).

\documentclass{standalone}
\usepackage{stackengine}
\usepackage{tikz,pgfplots}
    \usepgfplotslibrary{groupplots}
\begin{document}
\stackunder{%
  \begin{tikzpicture}
    \begin{axis}[width=4cm, height=4cm] \addplot coordinates{%
      (0,0) (1,2) (2,1)}; \end{axis}
  \end{tikzpicture}
  \begin{tikzpicture}
    \begin{axis}[width=4cm, height=4cm] \addplot coordinates{%
      (0,0) (1,2) (2,1)}; \end{axis}
  \end{tikzpicture}
}{%
  \begin{tikzpicture}
    \begin{axis}[width=4cm, height=4cm] \addplot coordinates{%
      (0,0) (1,2) (2,1)}; \end{axis}
  \end{tikzpicture}
}
\end{document}

enter image description here

Related Question