# How to rotate head row cell entries of pgfplotstable

How am I able to rotate the first entries of a table with pgfplotstable? I have the following table and want to rotate the descN labels in the first row.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{pgfplotstable}

\pgfplotstableset{
before row=\hline,
after row=\hline\hline
},
every last row/.style={
after row=\hline
},
every first column/.style={
},
every last column/.style={
column type=||l|
},
color cells/.style={
col sep=&,
row sep=\\,
string type,
postproc cell content/.code={%
\pgfkeysalso{@cell content=\rule{0cm}{2.4ex}%
\pgfmathsetmacro\y{max((##1 * 100), 0}%
\edef\temp{\noexpand\cellcolor{black!\y}}\temp%
\pgfmathtruncatemacro\x\y%
\ifnum\x>50 \color{white}\fi%
##1}%
},
columns/x/.style={
column name={},
postproc cell content/.code={}
}
}
}

\begin{document}
\begin{table}
\centering
\pgfplotstabletypeset[color cells]{
desc1 & desc2 & desc3 & desc4 & x \\
0.9 & 0.1 & 0 & 0 & desc1 \\
0 & 0.8 & 0.1 & 0.1 & desc2 \\
0 & 0 & 0.95 & 0.05 & desc3 \\
0 & 0.1 & 0.05 & 0.85 & desc3 \\
}
\end{table}
\end{document}

-

There must be another key to reach this but I can't remember it so I did it a little laborously.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{pgfplotstable}

\pgfplotstableset{
before row=\hline,
after row=\hline\hline,
typeset cell/.code={
\ifnum\pgfplotstablecol=\pgfplotstablecols
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\\}%
\else
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\rotatebox{90}{##1}&}%
\fi
}
},
every last row/.style={
after row=\hline
},
every first column/.style={
},
every last column/.style={
column type=||l|
},
color cells/.style={
col sep=&,
row sep=\\,
string type,
postproc cell content/.code={%
\pgfkeysalso{@cell content=\rule{0cm}{2.4ex}%
\pgfmathsetmacro\y{max((##1 * 100), 0}%
\edef\temp{\noexpand\cellcolor{black!\y}}\temp%
\pgfmathtruncatemacro\x\y%
\ifnum\x>50 \color{white}\fi%
##1}%
},
columns/x/.style={
column name={},
postproc cell content/.code={}
}
}
}

\begin{document}
\begin{table}
\centering
\pgfplotstabletypeset[color cells]{
desc1 & desc2 & desc3 & desc4 & x \\
0.9 & 0.1 & 0 & 0 & desc1 \\
0 & 0.8 & 0.1 & 0.1 & desc2 \\
0 & 0 & 0.95 & 0.05 & desc3 \\
0 & 0.1 & 0.05 & 0.85 & desc3 \\
}
\end{table}
\end{document}


-

I tried the solution given by @percusse, but it didn't show the desired result, e.g. no rotated header.

It seems that the typeset cell key is being ignored by the every head row selector - at least with pgfplotstable v1.5.1 that I am using.

A slight modification using the comment on another topic over at sf.net by Christian Feuersaenger did produce the desired output!

The key change is to apply the typeset cell on the whole table and use conditionals to isolate the part of the tabular we want to modify.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{pgfplotstable}

\pgfplotstableset{
%MODIFICATION START
typeset cell/.append code={%
\ifnum\pgfplotstablecol=\pgfplotstablecols%special treatment for last column
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\\}%
\else
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\rotatebox{90}{#1}&}%
\fi
\fi
},
before row=\hline,
after row=\hline\hline,
},
%MODIFICATION END
every last row/.style={
after row=\hline
},
every first column/.style={
},
every last column/.style={
column type=||l|
},
color cells/.style={
col sep=&,
row sep=\\,
string type,
postproc cell content/.code={%
\pgfkeysalso{@cell content=\rule{0cm}{2.4ex}%
\pgfmathsetmacro\y{max((##1 * 100), 0}%
\edef\temp{\noexpand\cellcolor{black!\y}}\temp%
\pgfmathtruncatemacro\x\y%
\ifnum\x>50 \color{white}\fi%
##1}%
},
columns/x/.style={
column name={},
postproc cell content/.code={}
}
}
}
\begin{document}
\begin{table}
\centering
\pgfplotstabletypeset[color cells]{
desc1 & desc2 & desc3 & desc4 & x \\
0.9 & 0.1 & 0 & 0 & desc1 \\
0 & 0.8 & 0.1 & 0.1 & desc2 \\
0 & 0 & 0.95 & 0.05 & desc3 \\
0 & 0.1 & 0.05 & 0.85 & desc3 \\
}
\end{table}
\end{document}


In my case I wanted to change the appearance of the head row, so may I suggest modifying the question to a more general form? that way more people with similar problems, like this closed question, will be drawn to this discussion.

Thanks again to @percusse and Christian Feuersaenger for pointing me to the right direction. I missed the importance of using \pgfkeyssetvalue in the manual ;)!

-
Oh I have version 1.6.1 indeed. –  percusse Oct 13 '12 at 23:07
Nice to see that that's an upcoming feature: I like your solution better! –  jhn Oct 13 '12 at 23:30
By the way, it's now the current version so it's released on CTAN. Hence you might want to update your version. And the question you've linked is closed because there was no MWE or any feedback from the OP. –  percusse Oct 14 '12 at 9:03