1

I'd like to try and plot non-numerical data to indicate some information for the usual numerical data. The former would then help understand the latter.

So in the MWE, it is only one column of extra data just to get this started, sort of. In this case it is binary data.

I thought it could possibly rather straightforward that not, i.e. to add the data with another \addplot command after I faked the data into a value (you'll notice it is the maximum value +2). Note: this of course means to always rework the data which the plot is based on, I'd happily use a method to not do that. :)

So I did that for the binary data but for the textual input, I do not know how approach. Since the different values AA, BB so forth relate to 1 object (the process) only, this is annoyingly more complex than I imagined. Would anyone happen to have a clever idea? :) I'd also be happy with a solution where one would not have to work in the data again to create the extra column. :)

Would it be possible to maybe have the content of the text column printed at 0.5*\ymax?

Picture of MWE

enter image description here

MWE

\documentclass{scrartcl}

\usepackage{pgfplotstable}

\begin{filecontents}{data.txt}
process,ColHeadAA,ColHeadBB,ColHeadCC,TEST,fake,text
1,17,19,15,yes,22,abc
2,10,8,11,no,,def
3,20,5,16,yes,22,GGG
4,14,4,10,no,,JJJ
\end{filecontents}

\pgfplotstableread[col sep=comma]{data.txt}{\mydata}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xlabel=x,
ylabel=Things,
ybar,
xtick=data,
]
\addplot table[x=process, y=ColHeadAA] {\mydata};
\addplot table[x=process, y=ColHeadBB] {\mydata};
\addplot [only marks, red] table[x=process, y=fake] {\mydata};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
henry
  • 6,594

1 Answers1

1

To automatically position the non-numeric data above the highest bar for each x coordinate, you can use y expr={max(\thisrow{ColHeadAA}, \thisrow{ColHeadBB})}. To print the non-numeric data, set point meta=explicit symbolic, nodes near coords in the \addplot options, and meta=TEST in the table options.

\documentclass{scrartcl}

\usepackage{pgfplots, pgfplotstable}

\begin{filecontents}{data.txt}
process,ColHeadAA,ColHeadBB,ColHeadCC,TEST,text
1,17,19,15,yes,abc
2,10,8,11,no,def
3,20,5,16,yes,GGG
4,14,4,10,no,JJJ
\end{filecontents}

\pgfplotstableread[col sep=comma]{data.txt}{\mydata}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xlabel=x,
ylabel=Things,
ybar,
xtick=data,
]
\addplot table[x=process, y=ColHeadAA] {\mydata};
\addplot table[x=process, y=ColHeadBB] {\mydata};
\addplot [only marks, nodes near coords, point meta=explicit symbolic]
    table [
        x=process,
        y expr={max(\thisrow{ColHeadAA}, \thisrow{ColHeadBB})},
        meta=TEST
    ] {\mydata};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
Jake
  • 232,450
  • Is it possible to to apply a style to the meta nodes? The usual code every node near coords/.append style={fill=white}, does not work as far as I can see. – henry Oct 18 '14 at 14:54
  • 1
    The style is called every node near coord (not every node near coords). – Jake Oct 18 '14 at 14:56