# GraphicsGrid with a Label for each Column and Row

Is it possible to use GraphicsGrid and do something like this?

$$\begin{array}{cccc} \text{X} & Label1 & Label2& Label3\\ Label4 & Plot1 & Plot2&Plot3\\ Label5 & Plot4 & Plot5&Plot6\\ Label6 & Plot7 & Plot8&Plot9\\ \end{array}$$

## 3 Answers

Here is an option:

plots = Table[Table[Plot[Sin[i x + j], {x, 1, 10}], {i, 3}], {j, 3}];
xlabels = {"", "Label 1", "Label 2", "Label 3"};
ylabels = {"Label 4", "Label 5", "Label 6"};
GraphicsGrid[Join[{xlabels}, Transpose[Join[{ylabels}, Transpose[plots]]]]]


Updated with a slightly prettier option:

xlabels = Text[Style[#, Large]] & /@ {"", "Label 1", "Label 2", "Label 3"};
ylabels = Text[Style[#, Large]] & /@ {"Label 4", "Label 5", "Label 6"};
Grid[Join[{xlabels}, Transpose[Join[{ylabels}, Transpose[plots]]]], Spacings -> {2, 1}]


If you are willing to forego GraphicsGrid and give up some control over the placement of the decorations, it can be as simple as this:

Make a 3 x 3 array of graphics (this is adopted from a previous answer}

circles[n_] :=
Module[{r, cntr},
r := RandomReal[.25];
cntr := RandomReal[1, {2}];
Graphics[Table[{EdgeForm[Black], Hue[RandomReal[]], Disk[cntr, r]}, n],
PlotRange -> {{0, 1}, {0, 1}}, PlotRangeClipping -> True, Frame -> True]

lines[] :=
Module[{lf, rt},
lf := With[{x = RandomReal[.48]}, {Red, Line[{{x, 0}, {x, 1}}]}];
rt := With[{x = RandomReal[{.52, 1}]}, {Blue, Line[{{x, 0}, {x, 1}}]}];
Graphics[{lf, rt},
PlotRange -> {{0, 1}, {0, 1}}, PlotRangeClipping -> True, Frame -> True]]

SeedRandom[4];
graphics =
Apply[
Show,
Partition[Transpose[{Table[circles[8], 9], Table[lines[], 9]}], 3],
{2}];


Make the headers:

{colHeaders, rowHeaders} = Partition[Table[Style[Row[{"Label", i}], "TBI"], {i, 6}], 3];


Make the grid with TableForm:

TableForm[graphics, TableHeadings -> {rowHeaders, colHeaders}]


You could construct Graphics for the row and column headings. Something like this. Would have to adjust the vertical / horizontal placement of the label text.

plotGrid = Table[Plot[Sin[x], {x, 0, 2 Pi}], 2, 2];

plotRowHeader =
Table[Graphics[Style[Text["Label " <> ToString[i]], 12]], {i, 2}];

plotColumnHeader =
Table[Graphics[Style[Text["Label " <> ToString[i]], 12]], {i, 3,
4}] // Prepend[Graphics[Style[Text["X"], 12]]];

graphicsGrid =
plotGrid // Prepend[plotRowHeader] // Transpose //
Prepend[plotColumnHeader];

GraphicsGrid[graphicsGrid]