I have a plot where I want to add a legend which is the combination of lines and marks. For that I want to replace (or define a new) the original pgf plots legend type. As said before, in the following MWE I want to replace the legend in the plot with one similar to the one that is bellow the graphic that uses the same symbols and lines as in the graphic. Is that possible?
\documentclass[10pt,border=0pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotstableread{%
x0 y1 y2 y3 y4 y5 y6
1 3.1 3.1 1.8 2.4 1.6 0.7
3 3.2 2.8 1.8 2.2 1.7 0.5
5 3.3 3.0 1.6 2.6 1.4 0.3
7 3.1 3.0 1.2 2.7 1.5 0.2
9 3.0 2.9 1.5 2.5 1.3 0.2
}{\testdata}
\usetikzlibrary{arrows}
\usetikzlibrary{plotmarks}
% mytick x interval=xmin:xstep:xmax
\pgfplotsset{mytick x interval/.style args={#1:#2:#3}{%
xmin=#1,xmax=#3,xincrement={#1}{#2},
xtick={#1,\xval,...,#3}
},
xincrement/.code 2 args={\pgfmathparse{#1+#2}\xdef\xval{\pgfmathresult}}
}
% mytick y interval=ymin:ystep:ymax
\pgfplotsset{mytick y interval/.style args={#1:#2:#3}{%
ymin=#1,ymax=#3,yincrement={#1}{#2},
ytick={#1,\yval,...,#3}
},
yincrement/.code 2 args={\pgfmathparse{#1+#2}\xdef\yval{\pgfmathresult}}
}
\pgfplotsset{every tick/.style={black,}}
\pgfplotsset{%
compat=1.8,
compat/show suggested version=false,
mytick x interval=1:2:9,
mytick y interval=0:0.5:4,
tick label style={font=\footnotesize},
label style={font=\footnotesize},
xlabel={x-label},
ylabel={y-label},
%enlargelimits=false,
legend style={%
font=\footnotesize,
legend cell align=left,
legend pos=south east,
nodes={inner xsep=2pt,inner ysep=0.4pt,text depth=0.15em},
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
legend entries={%
A,
B,
C,
S1,
S2,
},
mark options={fill=white,solid},
]
\addlegendimage{thick,only marks,mark=square*} \label{c1}
\addlegendimage{thick,only marks,mark=triangle*} \label{c2}
\addlegendimage{thick,only marks,mark=*} \label{c3}
\addlegendimage{thick} \label{l1}
\addlegendimage{thick,dashed} \label{l2}
%
\addplot[thick,mark=square*] table[x=x0,y=y2] {\testdata}; \label{n1}
\addplot[thick,dashed,mark=square*] table[x=x0,y=y1] {\testdata}; \label{n2}
\addplot[thick,mark=triangle*] table[x=x0,y=y4] {\testdata}; \label{n3}
\addplot[thick,dashed,mark=triangle*] table[x=x0,y=y3] {\testdata}; \label{n4}
\addplot[thick,mark=*] table[x=x0,y=y6] {\testdata}; \label{n5}
\addplot[thick,dashed,mark=*] table[x=x0,y=y5] {\testdata}; \label{n6}
\end{axis}
\end{tikzpicture}
\begin{tabular}{llll}
& & S1 & S2 \\
& & \ref{l1} & \ref{l2} \\
A & \ref{c1} & \ref{n1} & \ref{n2} \\
B & \ref{c2} & \ref{n3} & \ref{n4} \\
C & \ref{c3} & \ref{n5} & \ref{n6} \\
\end{tabular}
\end{document}

