5

I have the below data. I'd like to graph it such that there is a line for all rows for which bias, the last column, is zero, and another line for all rows for which bias is one. I thought perhaps this could be done by skipping rows based on bias=0, then adding another \addplot that skips rows when bias=1.

However, from section 4.21 of the pgfplots manual, I only see that rows can be skipped based on the values of the plotted points, not on a third variable.

Is there a way to skip points based on the value of a third variable? Or is there perhaps a better way to do this, without changing the form of the input file?

Thanks.

\documentclass{article}
\usepackage{pgfplotstable}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
xlabel=Period,
ylabel=ATE]
\addplot table[x=period,y=b] {
period b se z pvalue ll ul es bias
-4 -13.068966 4.7957403 -2.7251195 .00642782 -22.468444 -3.6694872 -.50936721 0
-3 -13.576271 2.9311518 -4.6317189 3.626e-06 -19.321223 -7.8313192 -.44067295 0
-2 -14.932203 2.8516346 -5.2363664 1.638e-07 -20.521304 -9.3431023 -.51395893 0
-1 -14.754237 2.3839111 -6.1890887 6.051e-10 -19.426617 -10.081857 -.52921471 0
0 -13.177966 2.9938464 -4.4016841 .00001074 -19.045797 -7.310135 -.47328062 0
0 -.83020764 2.8927267 -.2869983 .77411362 -6.4998477 4.8394324 -.47328062 1
1 -10.341667 3.0767608 -3.3612189 .00077599 -16.372007 -4.3113263 -.39240307 0
1 -1.6596195 2.7877028 -.59533588 .55161898 -7.1234166 3.8041776 -.39240307 1
};
\end{axis}
\end{tikzpicture}

\end{document}

1 Answer 1

5

You can use x expr to select the x coordinates:

\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=Period,
ylabel=ATE]

\pgfplotstableread{
period b se z pvalue ll ul es bias
-4 -13.068966 4.7957403 -2.7251195 .00642782 -22.468444 -3.6694872 -.50936721 0
-3 -13.576271 2.9311518 -4.6317189 3.626e-06 -19.321223 -7.8313192 -.44067295 0
-2 -14.932203 2.8516346 -5.2363664 1.638e-07 -20.521304 -9.3431023 -.51395893 0
-1 -14.754237 2.3839111 -6.1890887 6.051e-10 -19.426617 -10.081857 -.52921471 0
0 -13.177966 2.9938464 -4.4016841 .00001074 -19.045797 -7.310135 -.47328062 0
0 -.83020764 2.8927267 -.2869983 .77411362 -6.4998477 4.8394324 -.47328062 1
1 -10.341667 3.0767608 -3.3612189 .00077599 -16.372007 -4.3113263 -.39240307 0
1 -1.6596195 2.7877028 -.59533588 .55161898 -7.1234166 3.8041776 -.39240307 1
}\datatable

\addplot
  table[x expr={\thisrow{bias}==1?nan:\thisrow{period}},y=b]\datatable;
\addplot
  table[x expr={\thisrow{bias}==0?nan:\thisrow{period}},y=b]\datatable;
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.