# How to deal in pgfplots with repeated symbolic coords using data from a file

I am trying to generate a series of industrial plots resulting from a DoE, according to the example of the MWE, but I cannot find a way to generate it directly from a .csv file or \datatable, since the xticks gets duplicated for each occurence found in the .csv file. Is there a way to force all datapoints sharing the same symbolic xcoord to be aligned vertically, as in the example?

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=4cm, height =8cm}
\usepackage{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title= {Fatigue test results.},
only marks, mark size=0.5mm, enlarge x limits=0.3,
xlabel={Configuration},ylabel={Cycles before failure},
symbolic x coords={A,C}, xtick={A,C}]
\addplot coordinates {(A,1362)(A,2840) (A,687) (A,2771)};
\addplot coordinates {(C,2130)(C,3544) (C,1844)(C,3447)};
\end{axis}
\end{tikzpicture}

\begin{filecontents}{data1.csv}
config;cycles
A;1362
A;2840
A;687
A;2771
C;2130
C;3544
C;1844
C;3447
\end{filecontents}{data1.csv}

% what code could lead to the same plot, using the file or the datatable ?
% see below

\begin{tikzpicture}
\begin{axis}[
xtick=data,
title= {Fatigue test results.},
only marks, mark size=0.5mm, enlarge x limits=0.3,
xlabel={Configuration},ylabel={Cycles before failure},
symbolic x coords={A,C}]
\addplot table [x= config, y=cycles] \datatableone;
\end{axis}
\end{tikzpicture}

\end{document}


I guess you where searching for something like this ...

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
width=4cm,
height=8cm,
%
% put all common keys in a style
my style/.style={
title={Fatigue test results.},
only marks,
mark size=0.5mm,
enlarge x limits=0.3,
xlabel={Configuration},
ylabel={Cycles before failure},
symbolic x coords={A,C},
},
}
\usepackage{filecontents}
\begin{filecontents}{data1.csv}
config;cycles
A;1362
A;2840
A;687
A;2771
C;2130
C;3544
C;1844
C;3447
\end{filecontents}{data1.csv}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
% load the style
my style,
xtick={A,C},
]
\addplot coordinates {(A,1362)(A,2840) (A,687) (A,2771)};
\addplot coordinates {(C,2130)(C,3544) (C,1844)(C,3447)};
\end{axis}
\end{tikzpicture}

% what code could lead to the same plot, using the file or the datatable ?
% see below
\begin{tikzpicture}
\begin{axis}[
% load the style
my style,
xtick=data,
]
% define scatter classes so they match the previous plot
scatter/classes={
A={mark=*,blue},
C={mark=square*,red}
},
% use scatter plot and set the source to explicit symbolic'
scatter,
scatter src=explicit symbolic,
] table [
x=config,y=cycles,meta=config] \datatableone;
\end{axis}
\end{tikzpicture}
\end{document}
`

I have found a solution and added it to the code.