1

I am trying to create a Markov Map, as described by Dias & Vermunt 2007 in Fig. 2. http://members.home.nl/jeroenvermunt/dias2006c.pdf

Here is the figure:

enter image description here

So far I have tried using grids for TikZ, which is working for gradient colouring, but I cannot seem to add the state names. I have also tried with tables, but this result does not look nice (very messy, different size of cells).

(I hope this is done correctly, as it is my first time here!)

Is there anyone who knows how to add header names and create a nice map?

Thanks a lot!


I cannot figure out to respond on a comment.. So I will do it this way. The matrix library of Tikz works very well (I do get to see the results as posted in the comment), however when I extend it to a 22*22 matrix, an error appears:

Overfull \hbox - in nearly all paragraphs...

I tried changing the sizes size, minimum width and text width, but this did not help. Could you explain me what these measure mean and how to fix this? Thank You again!


I need several Markov maps next to each other, but the alignment does not work out as the bottom 2 maps are at different placings. Does someone know how to solve this? enter image description here

\begin{figure}[tb]
\subcaptionbox{Cluster 1, $\pi_1 = 0.18$}{
\begin{tikzpicture}[font=\ttfamily, ampersand replacement=\&]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
column 1/.style={nodes={draw=none, minimum width=30mm, text width=28mm, align=right}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{   \&  AC  \&  CH  \&  DP  \&  HP  \&  IA  \&  LB  \&  LP  \&  NL  \&  SC  \&  show\_discount\_reminder    \&  show\_funnel\_campaign  \&  show\_recc  \&  show\_recp  \&  show\_upsell    \&  show\_wijnatlas     \&  WV  \&  XT  \\                                      
AC  \& |[fill=black!    2   ]|\& |[fill=black!  0   ]|\& |[fill=black!  45  ]|\& |[fill=black!  6   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  37  ]|\& |[fill=black!  0   ]|\& |[fill=black!  3   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  5   ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        

XT  \& |[fill=black!    8   ]|\& |[fill=black!  0   ]|\& |[fill=black!  17  ]|\& |[fill=black!  17  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  25  ]|\& |[fill=black!  0   ]|\& |[fill=black!  13  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  17  ]|\& |[fill=black!  0   ]|\& |[fill=black!  2   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        
};
\end{tikzpicture}
}
\subcaptionbox{Cluster 2, $\pi_2 = 0.16$}{
\begin{tikzpicture}[font=\ttfamily, ampersand replacement=\&]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
%column 1/.style={nodes={draw=none, minimum width=43mm, text width=40mm, align=right}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{       AC  \&  CH  \&  DP  \&  HP  \&  IA  \&  LB  \&  LP  \&  NL  \&  SC  \&  show\_discount\_reminder    \&  show\_funnel\_campaign  \&  show\_recc  \&  show\_recp  \&  show\_upsell    \&  show\_wijnatlas     \&  WV  \&  XT  \\                                      
     |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  17  ]|\& |[fill=black!  2   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  79  ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        
     |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  14  ]|\& |[fill=black!  3   ]|\& |[fill=black!  0   ]|\& |[fill=black!  49  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  33  ]|\\                                                                    
};
\end{tikzpicture}
}
\subcaptionbox{Cluster 3, $\pi_3 = 0.23$}{
\begin{tikzpicture}[font=\ttfamily, ampersand replacement=\&]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
%row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
column 1/.style={nodes={draw=none, minimum width=30mm, text width=28mm, align=right}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{AC \& |[fill=black!    2   ]|\& |[fill=black!  0   ]|\& |[fill=black!  40  ]|\& |[fill=black!  10  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  40  ]|\& |[fill=black!  0   ]|\& |[fill=black!  7   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        

XT  \& |[fill=black!    4   ]|\& |[fill=black!  0   ]|\& |[fill=black!  18  ]|\& |[fill=black!  19  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  25  ]|\& |[fill=black!  1   ]|\& |[fill=black!  20  ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  9   ]|\& |[fill=black!  0   ]|\& |[fill=black!  2   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        
};
\end{tikzpicture}
}
\subcaptionbox{Cluster 4, $\pi_4 = 0.13$}{
\begin{tikzpicture}[font=\ttfamily, ampersand replacement=\&]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
%row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
%column 1/.style={nodes={draw=none, minimum width=43mm, text width=40mm, align=right}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{    |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  71  ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  6   ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  21  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        

     |[fill=black!  3   ]|\& |[fill=black!  0   ]|\& |[fill=black!  16  ]|\& |[fill=black!  11  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  19  ]|\& |[fill=black!  0   ]|\& |[fill=black!  6   ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  40  ]|\& |[fill=black!  0   ]|\& |[fill=black!  2   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        
};
\end{tikzpicture}
}
\subcaptionbox{Cluster 5, $\pi_5 = 0.17$}{
\begin{tikzpicture}[font=\ttfamily, ampersand replacement=\&]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
%row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
column 1/.style={nodes={draw=none, minimum width=43mm, text width=40mm, align=right}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{AC \& |[fill=black!    1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  17  ]|\& |[fill=black!  4   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  76  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        

XT  \& |[fill=black!    4   ]|\& |[fill=black!  0   ]|\& |[fill=black!  9   ]|\& |[fill=black!  28  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  29  ]|\& |[fill=black!  0   ]|\& |[fill=black!  13  ]|\& |[fill=black!  0   ]|\& |[fill=black!  3   ]|\& |[fill=black!  2   ]|\& |[fill=black!  0   ]|\& |[fill=black!  5   ]|\& |[fill=black!  8   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        
};
\end{tikzpicture}
}
\subcaptionbox{Cluster 6, $\pi_6 = 0.12$}{
\begin{tikzpicture}[font=\ttfamily, ampersand replacement=\&]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
%row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
%column 1/.style={nodes={draw=none, minimum width=43mm, text width=40mm, align=right}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{    |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  40  ]|\& |[fill=black!  6   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  18  ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  33  ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        

     |[fill=black!  7   ]|\& |[fill=black!  1   ]|\& |[fill=black!  8   ]|\& |[fill=black!  29  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  19  ]|\& |[fill=black!  0   ]|\& |[fill=black!  10  ]|\& |[fill=black!  0   ]|\& |[fill=black!  2   ]|\& |[fill=black!  15  ]|\& |[fill=black!  0   ]|\& |[fill=black!  2   ]|\& |[fill=black!  7   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                    
};
\end{tikzpicture}
}
\label{TP_userS6}
\caption{Transition probabilities of user data (ADJ) using MMM}
\end{figure}
2
  • 1
    Welcome to TeX.SE! Please, make complete small document begining with \documnetclass{...} and ending with \end{document}. It seems that matrix library from TikZ can servew well in your problem.
    – Zarko
    Commented Feb 2, 2017 at 15:33
  • Your last update is not related with the original one, so I think you should open a new question. When you do this, please follow Zarko's advice and provide a working code, from \documentclass to \end{document} and be sure that the provided code, although reduced, provides results similar to what is shown in the corresponding figure. In this case, tikz code produces different result.
    – Ignasi
    Commented Feb 16, 2017 at 9:08

2 Answers 2

4

You can use a matrix:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}[font=\sffamily\tiny]
\matrix (A) [nodes in empty cells,
        matrix of nodes,
        nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
        row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
        column 1/.style={nodes={draw=none, minimum width=12mm, text width=10mm, align=left}},
        column sep=-\pgflinewidth,
        row sep=-\pgflinewidth
        ]
{
& frontpage & news & tech \\
frontpage & |[fill=red]| & |[fill=orange]| & \\
news & & |[fill=red!70!black]| & \\
tech & & |[fill=yellow]| & |[fill=red!70!black]| \\
};
\end{tikzpicture}
\end{document}

enter image description here

Update:

The problem with the 22x22 matrix is not due to its size, but with the size of nodes is first column. In my previous example they were defined with

    column 1/.style={nodes={draw=none, minimum width=12mm, text width=10mm, align=left}},

with this size, they can fit frontpage, but not show\_discount\_reminer. If you declare column 1 nodes longer enough to cope with these long word, all messages about overfull horizontal box will desappear.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{matrix}

\usepackage{lipsum}

\begin{document}
\lipsum[1]

\begin{figure}[tb]
\begin{tikzpicture}[font=\itshape]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
column 1/.style={nodes={draw=none, minimum width=43mm, text width=40mm, align=left}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{
&   AC &  ACRC  &   CH  &   DP    &   HP    &   IA    &   infl\_discount\_reminder &   infl\_funnel\_campaign    &   infl\_upsell  &   infl\_wijnatlas   &   LB    &   LP    &   NL    &   SC    &   show\_discount\_reminder  &   show\_funnel\_campaign    &   show\_recc    &   show\_recp &  show\_upsell  &   show\_wijnatlas   &   WV &  XT \\
AC & |[fill=black!    1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   39  ]|& |[fill=black!   6   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   43  ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   8   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
ACRC  & |[fill=black! 40  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   20  ]|& |[fill=black!   20  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   20  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
CH    & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   4   ]|& |[fill=black!   1   ]|& |[fill=black!   1   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   18  ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   30  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   22  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   22  ]|\\
DP    & |[fill=black! 6   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   17  ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|& |[fill=black!   8   ]|& |[fill=black!   0   ]|& |[fill=black!   9   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   52  ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|\\
HP    & |[fill=black! 2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   7   ]|& |[fill=black!   49  ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   18  ]|& |[fill=black!   0   ]|& |[fill=black!   5   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   13  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   3   ]|\\
IA    & |[fill=black! 3   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   14  ]|& |[fill=black!   14  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   18  ]|& |[fill=black!   1   ]|& |[fill=black!   25  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   19  ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   1   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|\\
infl\_discount\_reminder  & |[fill=black! 2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   6   ]|& |[fill=black!   2   ]|& |[fill=black!   2   ]|& |[fill=black!   30  ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   33  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   19  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|\\
infl\_funnel\_campaign    & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   27  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   48  ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   22  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|\\
infl\_upsell  & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   64  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   36  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
infl\_wijnatlas   & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   64  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   27  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   9   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
LB    & |[fill=black! 5   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   13  ]|& |[fill=black!   22  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   32  ]|& |[fill=black!   0   ]|& |[fill=black!   8   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   14  ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
LP    & |[fill=black! 6   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   8   ]|& |[fill=black!   4   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|& |[fill=black!   36  ]|& |[fill=black!   0   ]|& |[fill=black!   8   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   18  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   15  ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|\\
NL    & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|& |[fill=black!   5   ]|& |[fill=black!   81  ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|\\
SC    & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   9   ]|& |[fill=black!   2   ]|& |[fill=black!   1   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|& |[fill=black!   4   ]|& |[fill=black!   0   ]|& |[fill=black!   47  ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   23  ]|& |[fill=black!   0   ]|& |[fill=black!   6   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|\\
show\_discount\_reminder  & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   82  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   7   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   5   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|\\
show\_funnel\_campaign    & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   81  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   5   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   5   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|\\
show\_recc    & |[fill=black! 3   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   11  ]|& |[fill=black!   4   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   13  ]|& |[fill=black!   0   ]|& |[fill=black!   19  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   34  ]|& |[fill=black!   0   ]|& |[fill=black!   4   ]|& |[fill=black!   6   ]|& |[fill=black!   0   ]|& |[fill=black!   4   ]|\\
show\_recp & |[fill=black!    0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   50  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   50  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
show\_upsell  & |[fill=black! 1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   4   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   6   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   4   ]|& |[fill=black!   0   ]|& |[fill=black!   45  ]|& |[fill=black!   1   ]|& |[fill=black!   3   ]|& |[fill=black!   32  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|\\
show\_wijnatlas   & |[fill=black! 10  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   12  ]|& |[fill=black!   3   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   43  ]|& |[fill=black!   0   ]|& |[fill=black!   7   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   21  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|\\
WV & |[fill=black!    0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   9   ]|& |[fill=black!   33  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   19  ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   24  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   10  ]|& |[fill=black!   3   ]|\\
XT & |[fill=black!    5   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   15  ]|& |[fill=black!   19  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   25  ]|& |[fill=black!   0   ]|& |[fill=black!   15  ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   14  ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
};
\end{tikzpicture}
\caption{Markov map aggregated data (S=1).}
\end{figure}  
\end{document}

enter image description here

1
  • @VivEUR You just need to change size of first column nodes. Look at updated answer. By the way, it's better to use italics text than $...$ because the space between letters is different.
    – Ignasi
    Commented Feb 3, 2017 at 8:58
2

An approach similar to the one you proposed in your question is the following. I use two loops to label the columns and rows, then some \fill for selected cells and finally the grid. The grid is drawn as the last step, so that the lines of the grid cover the edges of the filled cells.

\documentclass [border=2mm]{standalone}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=0.4]
    % Put column headers
    \foreach \header [count=\c] in {Lorem, ipsum, dolor, sit, amet, consectetur, adipiscing, elit, Proin, vulputate, dignissim, odio, eu, euismod, sapien, sodales, eu, Curabitur, ipsum, nibh, dictum, eu} {
      \node[above] at (\c-0.5,22) {\rotatebox{90}{\small\sffamily\header}};
      }

    % Put row headers
    \foreach \header [count=\c] in {Lorem, ipsum, dolor, sit, amet, consectetur, adipiscing, elit, Proin, vulputate, dignissim, odio, eu, euismod, sapien, sodales, eu, Curabitur, ipsum, nibh, dictum, eu} {
      \node[left] at (0,22-\c+0.5) {\small\sffamily\header};
      }

    % Fill some squares
    \fill[black!10] (0,21) rectangle +(1,1); % Use relative coordinates for the rectangle size
    \fill[black!30] (1,20) rectangle +(1,1); % Use relative coordinates for the rectangle size

    % Finally, the grid
    \draw[black, very thin] (0,0) grid (22,22);
\end{tikzpicture}
\end{document}

Result:

Result

You must log in to answer this question.

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