[Tex/LaTex] Simplest way to create a grid with colored squares and labels

graphstikz-pgf

I am trying to create a grid with colored squares, multi-line labels within the squares, and labels on the axes. Is there a simple and easy way to achieve this?

This question is the closest I could find to the answer, but I'm not sure how to add the second line of text in each box, or whether there is an easy way to add the rotated y-axis label (or the other labels for that matter). For this reason I am wondering whether a graph might be more suited.

This question is more along the lines of "is this easily possible and with what tool" rather than "what is the exact code to achieve this" (although that would be great as well). If the answer is "it's not easily possible" then that is fine, and I will look at alternative options.

The following image depicts what I am trying to produce:

enter image description here

Best Answer

Here, I do it with stacks. You can change the length of the box-edge to suit via the length \sqsz.

REVISED so that the color and category label are selected based on the box value (yellow-low <2, orange-med 3-7, red high >7)

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\usepackage{xcolor, graphicx}
\newlength\sqsz
\sqsz=1.4cm
\newcommand\sq[1]{\protect\sqhelper{#1}}
\newcommand\sqhelper[1]{\sffamily\bfseries\fboxsep=-\fboxrule%
  \ifnum#1>7\def\sqcolor{red}\def\sqcat{High}\else%
    \ifnum#1>2\def\sqcolor{orange}\def\sqcat{Med}\else%
      \def\sqcolor{yellow}\def\sqcat{Low}\fi\fi%
  \fcolorbox{black}{\sqcolor}{\makebox[\sqsz]{%
  \rule[\dimexpr-.5\sqsz+.2\ht\strutbox]{0pt}{\sqsz}\stackanchor[2pt]{#1}{(\sqcat)}}}}
\newcommand\hsq[1]{\protect\hsqhelper{#1}}
\newcommand\hsqhelper[1]{\sffamily\bfseries%
  \makebox[\sqsz]{\rule{0pt}{\dimexpr.5\sqsz+.2\ht\strutbox}#1}}
\newcommand\vsq[1]{\protect\vsqhelper{#1}}
\newcommand\vsqhelper[1]{\sffamily\bfseries%
  \rule[\dimexpr-.5\sqsz+.2\ht\strutbox]{0pt}{\sqsz}#1}
\begin{document}
\raisebox{.5\sqsz}{\rotatebox{-90}{\sffamily\bfseries\makebox[4\sqsz]{Impact of Event}}}~
\setstackgap{S}{0pt}
\Shortunderstack{\vsq{4}\\ \vsq{3}\\ \vsq{2}\\ \vsq{1}}~~
\stackunder[9pt]{%
  \Shortunderstack{
    \sq{4}\sq{8}\sq{12}\sq{16}\\
    \sq{3}\sq{6}\sq{9}\sq{12}\\
    \sq{2}\sq{4}\sq{6}\sq{8}\\
    \sq{1}\sq{2}\sq{3}\sq{4}\\
    \hsq{1}\hsq{2}\hsq{3}\hsq{4}
  }
}{\sffamily\bfseries Probability of event}
\end{document}

enter image description here