# How can I create the following graphic of raw data?

I've already tried different codes with tikzpicture but especially the normal distribution graphs are giving me headaches.

Any ideas?

Would appreciate any kind of help!

That is what I have got so far, but I have no clue how to integrate the normal distributions ...

\documentclass{article}
\usepackage{tikzsymbols}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

X Y
0 2
1 2.25
2 2.5
3 2.75
4 2
5 2.75
6 3
7 3.25
8 3.5
9 3.75
10 4
}\datatable

\begin{document}
\pgfplotsset{every axis legend/.append style={
cells={anchor=west}}}

\begin{tikzpicture}
\begin{axis}[legend pos=north west,xmin=0,xmax=10,
ymin=0,ymax=5,enlargelimits=0.1]

x=X,
y={create col/linear regression={y=Y}},
] {\datatable};
\xdef\slope{\pgfplotstableregressiona}
\xdef\offset{\pgfplotstableregressionb}
\addlegendentry{$E(Y | x_i)$}
\coordinate (aux1) at (2,{\slope*2+\offset});
\coordinate (aux2) at (2,2.5);
\end{axis}
\end{tikzpicture}
\end{document}

• Please show us the code you have so far! – Mensch Dec 2 '18 at 22:01
• you can certainly provide code to draw everything else apart from the normal distribution curves, given the answer(s) to your previous question. so please do.. – Troy Dec 2 '18 at 22:07

Here is a proposal: define a pic for the Gaussian and place it wherever you want.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{pgfplotstable}

X Y
0 2
1 2.25
2 2.5
3 2.75
4 2
5 2.75
6 3
7 3.25
8 3.5
9 3.75
10 4
}\datatable
\tikzset{pics/.cd,
Gaussian/.style={code={
\draw[gray] plot[variable=\x,domain=-\GaussDomain:\GaussDomain] ({\GaussHeight*exp(-2*\x*\x/\GaussWidth)},\x);
\draw[gray,dashed] (0,0) -- (\GaussHeight,0);
}}}
\pgfkeys{Gauss width/.store in=\GaussWidth,
Gauss width=0.5,
Gauss height/.store in=\GaussHeight,
Gauss height=0.8,
Gauss domain/.store in=\GaussDomain,
Gauss domain=1.2
}
\begin{document}
\pgfplotsset{every axis legend/.append style={
cells={anchor=west}}}

\begin{tikzpicture}
\begin{axis}[legend pos=north west,xmin=0,xmax=10,
ymin=0,ymax=5,enlargelimits=0.1]

x=X,
y={create col/linear regression={y=Y}},
] {\datatable};
\xdef\slope{\pgfplotstableregressiona}
\xdef\offset{\pgfplotstableregressionb}
\addlegendentry{$E(Y | x_i)$}