# String annotations to scatter plot coming from a different file

I am trying to adapt the setup to be found in this question. to the case where the names are in a different file. The main motivation is to have the same names for several plots and to be able to change them without altering the data files.

I tried to use the method to add a column from this question and produces the code below. I get the following error:

! Missing $inserted. <inserted text>$


which I fail to interpret. How can it be done?

\begin{tikzpicture}
\pgfplotstableset{
create on use/names/.style={
create col/copy column from table={names.dat}{names}
}
}
\begin{axis}[
visualization depends on={value \thisrow{names} \as \labela},
nodes near coords={\labela},
]

\addplot[scatter,only marks] table [x expr=\thisrowno{0},y expr=\thisrowno{1}] {data.dat};

\end{axis}
\end{tikzpicture}


data.dat:

1 1
2 4
3 7


names.dat:

Xyzzy
Plugh
Sheng

-

This doesn't work directly, unfortunately, because the create on use doesn't play well with the \thisrow{<name>} functionality. I think the best thing to do is the following:

1. Read the data.dat table into a temporary table macro.
2. Add the label column to the table.
3. Write the modified table to a temporary file using \pgfplotstablesave.

(these steps could be wrapped in a convenience macro, of course)

After that, you can access the names column exactly like you attempted:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots,pgfplotstable, filecontents}

\begin{filecontents*}{data.dat}
1 1
2 4
3 7
\end{filecontents*}
\begin{filecontents*}{names.dat}
labels
Xyzzy
Plugh
Sheng
\end{filecontents*}

\pgfplotstablecreatecol[outfile=temptable,create col/copy column from table={names.dat}{labels}]{names}\datatable
\pgfplotstablesave{\datatable}{temptable}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
visualization depends on=value\thisrow{names}\as\labela,
nodes near coords=\labela,
]

\addplot[scatter,only marks] table [x expr=\thisrowno{0},y expr=\thisrowno{1}] {temptable};

\end{axis}
\end{tikzpicture}
\end{document}

-