How can I create the following graphic of raw data?











up vote
1
down vote

favorite












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!



enter image description here



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}

pgfplotstableread{
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]

addplot[draw=none,color=red] table [
x=X,
y={create col/linear regression={y=Y}},
] {datatable};
xdefslope{pgfplotstableregressiona}
xdefoffset{pgfplotstableregressionb}
addplot[no marks,color=red,domain=-2:9] {slope*x+offset};
addlegendentry{$E(Y | x_i)$}
coordinate (aux1) at (2,{slope*2+offset});
coordinate (aux2) at (2,2.5);
end{axis}
end{tikzpicture}
end{document}









share|improve this question




















  • 3




    Please show us the code you have so far!
    – Kurt
    Dec 2 at 22:01






  • 1




    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 at 22:07















up vote
1
down vote

favorite












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!



enter image description here



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}

pgfplotstableread{
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]

addplot[draw=none,color=red] table [
x=X,
y={create col/linear regression={y=Y}},
] {datatable};
xdefslope{pgfplotstableregressiona}
xdefoffset{pgfplotstableregressionb}
addplot[no marks,color=red,domain=-2:9] {slope*x+offset};
addlegendentry{$E(Y | x_i)$}
coordinate (aux1) at (2,{slope*2+offset});
coordinate (aux2) at (2,2.5);
end{axis}
end{tikzpicture}
end{document}









share|improve this question




















  • 3




    Please show us the code you have so far!
    – Kurt
    Dec 2 at 22:01






  • 1




    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 at 22:07













up vote
1
down vote

favorite









up vote
1
down vote

favorite











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!



enter image description here



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}

pgfplotstableread{
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]

addplot[draw=none,color=red] table [
x=X,
y={create col/linear regression={y=Y}},
] {datatable};
xdefslope{pgfplotstableregressiona}
xdefoffset{pgfplotstableregressionb}
addplot[no marks,color=red,domain=-2:9] {slope*x+offset};
addlegendentry{$E(Y | x_i)$}
coordinate (aux1) at (2,{slope*2+offset});
coordinate (aux2) at (2,2.5);
end{axis}
end{tikzpicture}
end{document}









share|improve this question















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!



enter image description here



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}

pgfplotstableread{
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]

addplot[draw=none,color=red] table [
x=X,
y={create col/linear regression={y=Y}},
] {datatable};
xdefslope{pgfplotstableregressiona}
xdefoffset{pgfplotstableregressionb}
addplot[no marks,color=red,domain=-2:9] {slope*x+offset};
addlegendentry{$E(Y | x_i)$}
coordinate (aux1) at (2,{slope*2+offset});
coordinate (aux2) at (2,2.5);
end{axis}
end{tikzpicture}
end{document}






tikz-styles






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 2 at 22:31









Kurt

34.5k846157




34.5k846157










asked Dec 2 at 22:00









Rebecca

513




513








  • 3




    Please show us the code you have so far!
    – Kurt
    Dec 2 at 22:01






  • 1




    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 at 22:07














  • 3




    Please show us the code you have so far!
    – Kurt
    Dec 2 at 22:01






  • 1




    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 at 22:07








3




3




Please show us the code you have so far!
– Kurt
Dec 2 at 22:01




Please show us the code you have so far!
– Kurt
Dec 2 at 22:01




1




1




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 at 22:07




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 at 22:07










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










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}

pgfplotstableread{
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]

addplot[draw=none,color=red] table [
x=X,
y={create col/linear regression={y=Y}},
] {datatable};
xdefslope{pgfplotstableregressiona}
xdefoffset{pgfplotstableregressionb}
addplot[no marks,color=red,domain=-2:9] {slope*x+offset}
coordinate[pos=0.3](p1) coordinate[pos=0.7](p2);
addlegendentry{$E(Y | x_i)$}
% coordinate (aux1) at (2,{slope*2+offset});
% coordinate (aux2) at (2,2.5);
end{axis}
path foreach X in {1,2} {(pX) pic{Gaussian}};
end{tikzpicture}
end{document}


You can adjust the width, height, domain or color of the Gaussian by setting the corresponding pgf keys accordingly.



enter image description here






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "85"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f462859%2fhow-can-i-create-the-following-graphic-of-raw-data%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    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}

    pgfplotstableread{
    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]

    addplot[draw=none,color=red] table [
    x=X,
    y={create col/linear regression={y=Y}},
    ] {datatable};
    xdefslope{pgfplotstableregressiona}
    xdefoffset{pgfplotstableregressionb}
    addplot[no marks,color=red,domain=-2:9] {slope*x+offset}
    coordinate[pos=0.3](p1) coordinate[pos=0.7](p2);
    addlegendentry{$E(Y | x_i)$}
    % coordinate (aux1) at (2,{slope*2+offset});
    % coordinate (aux2) at (2,2.5);
    end{axis}
    path foreach X in {1,2} {(pX) pic{Gaussian}};
    end{tikzpicture}
    end{document}


    You can adjust the width, height, domain or color of the Gaussian by setting the corresponding pgf keys accordingly.



    enter image description here






    share|improve this answer



























      up vote
      2
      down vote



      accepted










      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}

      pgfplotstableread{
      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]

      addplot[draw=none,color=red] table [
      x=X,
      y={create col/linear regression={y=Y}},
      ] {datatable};
      xdefslope{pgfplotstableregressiona}
      xdefoffset{pgfplotstableregressionb}
      addplot[no marks,color=red,domain=-2:9] {slope*x+offset}
      coordinate[pos=0.3](p1) coordinate[pos=0.7](p2);
      addlegendentry{$E(Y | x_i)$}
      % coordinate (aux1) at (2,{slope*2+offset});
      % coordinate (aux2) at (2,2.5);
      end{axis}
      path foreach X in {1,2} {(pX) pic{Gaussian}};
      end{tikzpicture}
      end{document}


      You can adjust the width, height, domain or color of the Gaussian by setting the corresponding pgf keys accordingly.



      enter image description here






      share|improve this answer

























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        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}

        pgfplotstableread{
        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]

        addplot[draw=none,color=red] table [
        x=X,
        y={create col/linear regression={y=Y}},
        ] {datatable};
        xdefslope{pgfplotstableregressiona}
        xdefoffset{pgfplotstableregressionb}
        addplot[no marks,color=red,domain=-2:9] {slope*x+offset}
        coordinate[pos=0.3](p1) coordinate[pos=0.7](p2);
        addlegendentry{$E(Y | x_i)$}
        % coordinate (aux1) at (2,{slope*2+offset});
        % coordinate (aux2) at (2,2.5);
        end{axis}
        path foreach X in {1,2} {(pX) pic{Gaussian}};
        end{tikzpicture}
        end{document}


        You can adjust the width, height, domain or color of the Gaussian by setting the corresponding pgf keys accordingly.



        enter image description here






        share|improve this answer














        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}

        pgfplotstableread{
        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]

        addplot[draw=none,color=red] table [
        x=X,
        y={create col/linear regression={y=Y}},
        ] {datatable};
        xdefslope{pgfplotstableregressiona}
        xdefoffset{pgfplotstableregressionb}
        addplot[no marks,color=red,domain=-2:9] {slope*x+offset}
        coordinate[pos=0.3](p1) coordinate[pos=0.7](p2);
        addlegendentry{$E(Y | x_i)$}
        % coordinate (aux1) at (2,{slope*2+offset});
        % coordinate (aux2) at (2,2.5);
        end{axis}
        path foreach X in {1,2} {(pX) pic{Gaussian}};
        end{tikzpicture}
        end{document}


        You can adjust the width, height, domain or color of the Gaussian by setting the corresponding pgf keys accordingly.



        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 3 at 3:59

























        answered Dec 2 at 22:39









        marmot

        81.7k491174




        81.7k491174






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f462859%2fhow-can-i-create-the-following-graphic-of-raw-data%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Can I use Tabulator js library in my java Spring + Thymeleaf project?