# Switch from in-code data table to external file in macro

I have used the very nice grouping macro described here:

How can I mix an "ybar" and an "ybar stacked" with pgfplots?

I would like to be able to use it with data that I have read from a file. How can that be achieved? Instead of the data table written into the tex file, I would like to have it outside, in its own file. How can I do that so that the references to \datatable in the grouping function still work?

-
See "4.2.8 Reading coordinates From Files" on page 51 of the pgfplots manual. – Luigi Oct 11 '12 at 9:53
I have read data from files for plots (as described in the manual), and although I have had no trouble plotting in that way, I have not been able to make the grouping function I linked to work when I read data from a file. Perhaps setting a label to the table read from a file would work, but I have not succeeded in doing that. – hjb981 Oct 11 '12 at 10:07

Let `mytable.dat` be you data file, then substitute all the `\pgfplotstableread` environment with

``````\pgfplotstableread{mytable.dat}\datatable
``````

and that's all.

-
I thought I had tried that, but I must have done something wrong earlier, because it did indeed work. – hjb981 Oct 11 '12 at 11:03