# plot data with pgfplots if meta column meets criteria

I have a data file with many columns, and I want to plot bwgstar vs servers for n=2. So n is the meta column, servers is on the x-axis, and bwgstar is on the y-axis. I want to do this within the latex document so that I can regenerate the data later.

A shortened version of some data appears below.

  k    n    servers   switches   degree   diameter   bwg      bwgstar   difference   t
2    2    8         4          2        4          2        2         0            1
2    3    36        9          4        5          8        6         2            3
2    4    96        16         6        5          16       16        0            8
2    5    200       25         8        5          36       30        6            10
2    6    360       36         10       5          54       54        0            13
2    7    588       49         12       5          96       84        12           21
3    2    24        8          3        6          4        4         0            4
3    3    162       27         6        7          26       22        4            10
3    4    576       64         9        7          64       64        0            32


You can adapt the approach from Filter rows from a table:

\documentclass[border=5mm]{standalone}

\usepackage{filecontents}

\usepackage{pgfplots}
\pgfplotsset{
x filter/.code={
\ifnum\thisrow{#1}=#2
\else
\def\pgfmathresult{nan}
\fi
}
}
}

\begin{filecontents}{data.dat}
k    n    servers   switches   degree   diameter   bwg      bwgstar   difference   t
2    2    8         4          2        4          2        2         0            1
2    3    36        9          4        5          8        6         2            3
2    4    96        16         6        5          16       16        0            8
2    5    200       25         8        5          36       30        6            10
2    6    360       36         10       5          54       54        0            13
2    7    588       49         12       5          96       84        12           21
3    2    24        8          3        6          4        4         0            4
3    3    162       27         6        7          26       22        4            10
3    4    576       64         9        7          64       64        0            32
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}